Variable memory address

Is it possible to get the memory address of a variable in C #.

What I'm trying to do is very simple. I want to declare variables of type Double, Float, Decimal and assign a value of 1.1 to each of these variables. Then I would like to see how these values ​​are represented in memory. I need to get the memory address of a variable to see how it is stored in memory. When I have a memory address I plan to put a breakpoint in the code and use Debug -> Windows -> Memory in the visual studio to see how the numbers are stored in memory.

Greetings

+3
source share
3 answers

, , BitConverter, . #, , , .

, BitConverter , , &varname, .

+4

tyranid, , - . , ILdasm , , , #. #: -

double d1 = 21.1;
decimal d2 = 22.1M;
float d3 = 21.1F;

IL- ILDasm, , # : -

//000012:             double d1 = 21.1;
  IL_0001:  ldc.r8     21.100000000000001
..............
//000013:             decimal d2 = 22.1M;
  IL_000b:  ldc.i4     0xdd
...............
//000014:             float d3 = 21.1F;
  IL_001a:  ldc.r4     21.1

, ​​ .

+1

Source: https://habr.com/ru/post/1740099/


All Articles