sizeof

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

What is the equivalent of sizeof in VB.NET?
In C# you can write:
nTotalSize += sizeof(int);

what is the equivalent in VB.NET?
 
Tom Shelton provided this advice:

monitorInfo.cbSize = Marshal.SizeOf(monitorInfo)
 
scorpion53061 said:
Tom Shelton provided this advice:

monitorInfo.cbSize = Marshal.SizeOf(monitorInfo)

ACK. Notice that this will require an "instance" of the type instead of the
type name.
 
You're wrong there.
Look carefully at the overloads and you will see that one of them takes a
type 'Object', the other takes a type 'Type'.

Try this:

Imports System.Runtime.InteropServices
Module Module1
Sub Main()
Debug.WriteLine(Marshal.SizeOf(GetType(Int32)))
End Sub
End Module


No objects constructed.
 
What prompted you to suggest this, are we talking about different versions of
the .NET framework or something? You sounded pretty sure.
 
I would use DirectCast but hey it works....



Bonj said:
You're wrong there.
Look carefully at the overloads and you will see that one of them takes a

type 'Object', the other takes a type 'Type'.

Try this:

Imports System.Runtime.InteropServices
Module Module1
Sub Main()
Debug.WriteLine(Marshal.SizeOf(GetType(Int32)))
End Sub
End Module


No objects constructed.
 
Bonj said:
What prompted you to suggest this, are we talking
about different versions of the .NET framework or
something? You sounded pretty sure.

No, you are right, I missed the overload.
 

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