Atlanta Custom Software Development 

 
   Search        Code/Page
 

User Login
Email

Password

 

Forgot the Password?
Services
» Web Development
» Maintenance
» Data Integration/BI
» Information Management
Programming
  Database
Automation
OS/Networking
Graphics
Links
Tools
» Regular Expr Tester
» Free Tools

Determine the size of a structure

Total Hit ( 4614)

Rate this article:     Poor     Excellent 

 Submit Your Question/Comment about this article

Rating


 


Unlike previous Visual Basic versions, under VB.NET you can't use the Len function to calculate the length of a Structure or a class. However, it is easy to get this information with the SizeOf static method of the System.Runtime.InteropServices.Mashal class, as in:

Click here to copy the following block
Imports System.Runtime.InteropServices

Module Module1
  ' Notice that this structure contains 2 padding bytes between
  ' the first two elements
  Structure MyStruct
    Public el1 As Short
    Public el2 As Integer
    Public el3 As String
  End Structure

  Sub Main(ByVal args() As String)
    Dim struct As mystruct
    Console.WriteLine(Marshal.SizeOf(struct))  ' => 12
  End Sub
End Module


Submitted By : Nayan Patel  (Member Since : 5/26/2004 12:23:06 PM)

Job Description : He is the moderator of this site and currently working as an independent consultant. He works with VB.net/ASP.net, SQL Server and other MS technologies. He is MCSD.net, MCDBA and MCSE. In his free time he likes to watch funny movies and doing oil painting.
View all (893) submissions by this author  (Birth Date : 7/14/1981 )


Home   |  Comment   |  Contact Us   |  Privacy Policy   |  Terms & Conditions   |  BlogsZappySys

© 2008 BinaryWorld LLC. All rights reserved.