Turning around Harper Shelby's answer, yes, it can be done, but, as a rule, this is the smell of code for this in .NET.
To get the address of a variable in C #, you can use C-style pointer syntax (*) / address (+ amp;) / dereference (->). To do this, you will need to compile the application using the / unsafe compiler, since you exit the secure network of managed code as soon as you start accessing the memory addresses directly.
An example from MSDN tells most of the story:
int number;
int* p = &number;
Console.WriteLine("Value pointed to by p: {0}", p->ToString());
This assigns the address of the variable to numberpointer-to-int p.
There are some catches:
- The variable whose address you select must be initialized. Not a problem for value types that are by default, but a problem for reference types.
- In .NET, variables can move in memory without knowing it. If you need to deal with the address of a variable, you really want to use
fixedto bind the variable in RAM. - & , . ( ,
int* p = &GetSomeInt();) - , , CLR, .
, - , , .NET. .NET , , . () , ; , , , , , .
, , , , .