 
  Data Structure Data Structure
 Networking Networking
 RDBMS RDBMS
 Operating System Operating System
 Java Java
 MS Excel MS Excel
 iOS iOS
 HTML HTML
 CSS CSS
 Android Android
 Python Python
 C Programming C Programming
 C++ C++
 C# C#
 MongoDB MongoDB
 MySQL MySQL
 Javascript Javascript
 PHP 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 find the size of a variable without using sizeof in C#?
To get the size of a variable, sizeof is used.
int x; x = sizeof(int);
To get the size of a variable, without using the sizeof, try the following code −
// without using sizeof byte[] dataBytes = BitConverter.GetBytes(x); int d = dataBytes.Length;
Here is the complete code.
Example
using System; class Demo {    public static void Main() {       int x;       // using sizeof       x = sizeof(int);       Console.WriteLine(x);       // without using sizeof       byte[] dataBytes = BitConverter.GetBytes(x);       int d = dataBytes.Length;       Console.WriteLine(d);    } }  Output
4 4
Advertisements
 