
- C# Basic Tutorial
- C# - Home
- C# - Overview
- C# - Environment
- C# - Program Structure
- C# - Basic Syntax
- C# - Data Types
- C# - Type Conversion
- C# - Variables
- C# - Constants
- C# - Operators
- C# - Decision Making
- C# - Loops
- C# - Encapsulation
- C# - Methods
- C# - Nullables
- C# - Arrays
- C# - Strings
- C# - Structure
- C# - Enums
- C# - Classes
- C# - Inheritance
- C# - Polymorphism
- C# - Operator Overloading
- C# - Interfaces
- C# - Namespaces
- C# - Preprocessor Directives
- C# - Regular Expressions
- C# - Exception Handling
- C# - File I/O
- C# Advanced Tutorial
- C# - Attributes
- C# - Reflection
- C# - Properties
- C# - Indexers
- C# - Delegates
- C# - Events
- C# - Collections
- C# - Generics
- C# - Anonymous Methods
- C# - Unsafe Codes
- C# - Multithreading
- C# Useful Resources
- C# - Questions and Answers
- C# - Quick Guide
- C# - Useful Resources
- C# - Discussion
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
- Related Articles
- How to find the size of a variable without using sizeof in C#?
- What is the use of sizeof Operator in C#?
- How to check the type of a variable or object in JavaScript?
- How to get the variable data type in PowerShell?
- Sizeof operator in C
- How do we use enum keyword to define a variable type in C#?
- Find size of array in C/C++ without using sizeof
- Result of sizeof operator using C++
- How can we amend the declared size of a column’s data type in MySQL?
- What should one use CHAR data type or VARCHAR data type in MySQL?
- What is the type conversion operator ( ) in Java and how to use it?
- What is sizeof operator in C++?
- How to use a final or effectively final variable in lambda expression in Java?
- How to use or operator in MongoDB to fetch records on the basis of existence?
- How to use blob data type in Android sqlite?

Advertisements