sizeof

  • Thread starter Thread starter Roberto Lopes
  • Start date Start date
R

Roberto Lopes

Hi!,
I have a class in which I have, lets say 8 int members;
I need to know the size of that class ( which is now 8 * 4 bytes ).
In C, we used sizeof( myClass ), but I can't find how to do it in C#.
Any idea how to do it the .Net way ? ( besides using unsafe and sizeof)

Thanks
 
Roberto,

Unsafe is really the only way to do it. However, this isn't the true
size of your class (due to things such as method tables and whatnot).

What is it you are trying to do?
 
You will want to look at the Marshal class since sizeof() is for unsafe
codeblocks only. Marshal class has the ability to get the unmanaged storage
requirements of a struct, for instance.

This isn't usually something you need to concern yourself with in the
managed world. Ever.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top