Claire,
The reason for this is that the SizeOf method on the Marshal class
determines the size of the managed type after it is marshaled to the
unmanaged realm. Because characters are marshaled as 8-bit ASCII characters
by default, that is why you get a value of 1.
There is no direct way to get the size of a type in .NET without hooking
into the profiling APIs (which is not an easy task, especially from within
managed code).
Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
-
mv*@spam.guard.caspershouse.com
"Claire" <as*******@ntlworld.com> wrote in message
news:O7**************@TK2MSFTNGP09.phx.gbl...
char a = 'p';
if (System.Runtime.InteropServices.Marshal.SizeOf(a) == 1)
dothis();
else
dothat();
SizeOf(a) is returned as 1. I thought chars were 16 bits in size. Why is
it returning 1 to me?
thanks
Claire