Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

39,948 questions

51,890 answers

573 users

How to get the size of data types in C#

1 Answer

0 votes
using System;

namespace ConsoleApplication_C_Sharp
{
    class Program
    {
        static void Main(string[] args)
        {
            int size = sizeof(byte);
            Console.WriteLine(size); // 1

            size = sizeof(int);
            Console.WriteLine(size); // 4

            size  = sizeof(Int16); // short // 2
            Console.WriteLine(size);

            size = sizeof(Int32); // int // 4
            Console.WriteLine(size);

            size = sizeof(Int64); // long // 8
            Console.WriteLine(size);

            size = sizeof(char);
            Console.WriteLine(size); // 2

            size = sizeof(bool);
            Console.WriteLine(size); // 1

            size = sizeof(double);
            Console.WriteLine(size); // 8           

            size = sizeof(decimal);
            Console.WriteLine(size); // 16
        }
    }
}

/*
run:
   
1
4
2
4
8
2
1
8
16

*/

 



answered Jan 18, 2017 by avibootz

Related questions

1 answer 175 views
1 answer 264 views
1 answer 134 views
1 answer 181 views
1 answer 137 views
137 views asked Jan 12, 2017 by avibootz
1 answer 149 views
149 views asked Jan 12, 2017 by avibootz
...