Looking at the docs to Marshal.SizeOf(Type), I would expect typeof(char) to return 1 -- the default interpretation of a Char is in ANSI/MBCS (look at the Remarks for the SizeOf documentation pointing you to the CharSet enumeration: http://msdn2.microsoft.com/en-us/library/system.runtime.interopservices.char set.aspx), so Marshal.SizeOf(typeof(char)) == sizeof(char) == 1 byte.
I would try another example (I'm on a machine without VS installed! Oh the horror!), as Marshal.SizeOf(typeof(char)) would give potentially erroneous results depending on current settings. Good luck. Andrew (Just a reminder that there is no guarantee in managed code that contiguous array elements are arranged continuously in memory; unless you pin and control the memory yourself, you're guessing at an underlying implementation.) > -----Original Message----- > From: Discussion of advanced .NET topics. [mailto:ADVANCED- > [EMAIL PROTECTED] On Behalf Of Curt Hagenlocher > Sent: Wednesday, April 16, 2008 9:07 PM > To: ADVANCED-DOTNET@DISCUSS.DEVELOP.COM > Subject: Re: [ADVANCED-DOTNET] Getting managed size of a generic > parameter > > On Wed, Apr 16, 2008 at 8:31 PM, Sébastien Lorion > <[EMAIL PROTECTED]> wrote: > > I want the managed size, so Marshal.SizeOf does not return the > correct value. > > > > For example, sizeof(char) returns 2 and Marshal.SizeOf(typeof(char)) > returns 1. > > Huh. So it does. Are there any other types for which this is true? > > Some quality time with a search engine suggests that there's no other > way to get any kind of size at runtime. > > -- > Curt Hagenlocher > [EMAIL PROTECTED] > > =================================== > This list is hosted by DevelopMentor® http://www.develop.com > > View archives and manage your subscription(s) at > http://discuss.develop.com =================================== This list is hosted by DevelopMentor® http://www.develop.com View archives and manage your subscription(s) at http://discuss.develop.com