sizeof() Operator in C#
Last Updated :
28 May, 2020
The sizeof() operator is used to obtain the size of a data type in bytes in bytes. It will not return the size of the variables or instances. Its return type is always int.
Syntax:
int sizeof(type);
Examples:
Input : sizeof(byte);
Output : 1
Input : sizeof(int);
Output : 4
using System;
using System.IO;
using System.Text;
namespace IncludeHelp
{
class Test
{
static void Main( string [] args)
{
Console.WriteLine( "sizeof(char) : {0}" , sizeof ( char ));
Console.WriteLine( "sizeof(byte) : {0}" , sizeof ( byte ));
Console.WriteLine( "sizeof(sbyte) : {0}" , sizeof ( sbyte ));
Console.WriteLine( "sizeof(float) : {0}" , sizeof ( float ));
Console.WriteLine( "sizeof(ushort) : {0}" , sizeof ( ushort ));
Console.WriteLine( "sizeof(double) : {0}" , sizeof ( double ));
Console.WriteLine( "sizeof(int) : {0}" , sizeof ( int ));
Console.WriteLine( "sizeof(bool) : {0}" , sizeof ( bool ));
Console.WriteLine( "sizeof(short) : {0}" , sizeof ( short ));
}
}
}
|
Output:
sizeof(char) : 2
sizeof(byte) : 1
sizeof(sbyte) : 1
sizeof(float) : 4
sizeof(ushort) : 2
sizeof(double) : 8
sizeof(int) : 4
sizeof(bool) : 1
sizeof(short) : 2
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...