Well...not like that: that wouldn't work in any language, since a
byte
variable can't hold the address of
anything - they are only 8 bits, and addresses these days are at least 32.
And there is a problem here in that an array isn't a structure at all, it's always a class (and so a reference type), even if the datatype it is an array
of are value types.
You can get the address of things in C#, but you need to use
unsafe
code and pointers. which is:
A) Deliberatley difficult to do
B) Dangerous - which is why it's called
unsafe
code.
Under normal circumstances you don't need pointers or addresses in C#: the CLR and references take care of all that for you.
What are you trying to do that you think you need this?
"i need array[0]'s address"
It doesn't really have one.
Well...it does...but it moves...
The problem is that an array is a reference type, which means the whole array is located on the managed heap - which means that the Garbage Collector (which you have no control of, or idea of when it runs) is at liberty to move it at any time.
So if you do manage to get the actual "physical memory" address of the first element in the array, it could be invalid by the time you actually use it - even if that is the next instruction in your code. Now, there are ways round that, but it's unusual, and somewhat dangerous.
You can get a reference of the first element in the array - if it's a reference type - very easily:
string[] array = new string[10];
for (int i = 0; i < 10; i++)
array[i] = string.Format("Element {0}", i);
...
string s = array[0];
Why are you trying to get the address of anything? what are you planning on doing with it when you have it? Because I can't help thinking there is something missing here...