The main purpose of "Dot Net Labs" provide the dot net program. You can learn dot net, .Net Core, C#, SQL, Linq step-by-step.

Saturday, 30 May 2015

SIZEOF Keyword Example : It shows the size of Data types


We will learn about sizeof() with the help of the example. Here sizeof() is an operator in c#. It used to obtain the size of a data type in bytes and works only on compile-time. It does not work with the variable and instance.

Example:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace DataTypesDemo
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("The size of short is {0} bytes.",sizeof(short));
Console.WriteLine("The size of int is {0} bytes.", sizeof(int));
Console.WriteLine("The size of long is {0} bytes.", sizeof(long));
Console.WriteLine("The size of float is {0} bytes.", sizeof(float));
Console.WriteLine("The size of double is {0} bytes.", sizeof(double));
Console.WriteLine("The size of char is {0} bytes.", sizeof(char));

Console.ReadLine();
}
}
}




0 comments:

Post a Comment

Do not enter spam link

Popular Posts