

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
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 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
- Related Questions & Answers
- Find size of array in C/C++ without using sizeof
- How to use sizeof() operator to find the size of a data type or a variable in C#
- How to swap two numbers without using a temp variable in C#
- How to find the size of a list in C#?
- How to swap two numbers without using the third or a temporary variable using C Programming?
- Result of sizeof operator using C++
- Swapping two variable value without using third variable in C/C++
- How to find the size of localStorage in HTML?
- How to swap two arrays without using temporary variable in C language?
- Why is not sizeof for a struct equal to the sum of sizeof of each member in C/C++?
- Find the size of a HashMap in Java
- How can I swap two strings without using a third variable in Java?
- Python program to Find the size of a Tuple
- How to find the mean of each variable using dplyr by factor variable with ignoring the NA values in R?
- Write a Golang program to swap two numbers without using a third variable
Advertisements