Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to use sizeof() operator to find the size of a data type or a variable in C#
The sizeof() datatype returns the size of a data type. Let’s say you need to find the size of int datatype −
sizeof(int);
For double datatype
sizeof(double);
Let us see the complete example to find the size of various datatypes −
Example
using System;
namespace Demo {
class Program {
static void Main(string[] args) {
Console.WriteLine("The size of int is {0}", sizeof(int));
Console.WriteLine("The size of int is {0}", sizeof(char));
Console.WriteLine("The size of short is {0}", sizeof(short));
Console.WriteLine("The size of long is {0}", sizeof(long));
Console.WriteLine("The size of double is {0}", sizeof(double));
Console.ReadLine();
}
}
}
Output
The size of int is 4 The size of int is 2 The size of short is 2 The size of long is 8 The size of double is 8
Advertisements