- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace ConsoleApplication1
- {
- class Program
- {
- static void Main(string[] args)
- {
- String s= "hello world";
- Console.WriteLine("This is the size of integer: {0}", sizeof(int));
- Console.WriteLine("Size of Charachter is :{0}", sizeof(char));
- Console.WriteLine("Size of String is: {0}", s.Count()); // Remember you cant use size of function for a string as string variable does not have a predefined size
- // String will also count whitespaces | Count function counts the charachters and whitespaces for value stored in string
- Console.WriteLine("Size of double variable is:{0}",sizeof(double));
- Console.WriteLine("Size of float variable is:{0}", sizeof(float));
- Console.WriteLine("Size of boolean type is:{0}", sizeof(bool));
- Console.WriteLine("Size of long integer is:{0}", sizeof(long));
- Console.WriteLine("Size of short integer is: {0}", sizeof(short));
- Console.WriteLine("Size of a byte type is :{0}", sizeof(byte)); // Not used much
- Console.WriteLine("Size of Decimal Type is:{0}", sizeof(decimal)); // Not used much
- Console.WriteLine("Size of sbyte type is:{0}", sizeof(sbyte)); // Not used much
- Console.WriteLine("Size of ushort int is:{0}", sizeof(ushort)); // Not used much
- Console.WriteLine("Size of uint is:{0}", sizeof(uint)); // Not used much
- Console.WriteLine("Size of longint is:{0}", sizeof(ulong)); // Not used much
- Console.ReadKey(); //Screen Stays when you debug using f5 and does not vanish away
- }
- }
- }
This program show how to Print the Size of each Data Type.
