as far as I understand the spec, sizeof() only works on types, not instances in C#.
And the other option of getting sizes of structs in .NET, Marshal.SizeOf(), seems unavailable in MF - or am I missing anything?
Although that seems to be unrelated here (since my example doesn’t use any pointers) this is interesting. I was not aware that pointers were not supported in MF. So that inspires me to more experiments now, of course…
unsafe public static void F()
int a = 1;
int* aptr = &a;
int b = *aptr;
Debug.Print("a: " + a + " b: " + b + "\r\n");
compiles without complaint, but throws an exception on the Debug.Print() statement (although the interesting pointer stuff happens before).
But if I only use Print() outside the unsafe function, everything seems to work alright:
public static void Main()
byte b = F();
Debug.Print("b: " + b + "\r\n");
unsafe public static byte F()
int a = 1;
byte* aptr = (byte*)&a;
Modifying aptr inside F() does throw an exception, though. So that “pointers support” may not be of any use if you can’t do pointer arithmetics…
I would love to read some background of unsafe/pointer support in MF, if anybody can provide any links.