C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Communities   Interview   Jobs   Projects   Offshore Development    
Silverlight Tutorials | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Revenue Sharing |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...

New Feature: Community Sites: Create your own .NET community website and start earning from Google AdSense ! It's Free !




Structures in VB.NET - Part II (Defining a structure)


Posted Date: 11 Mar 2004    Resource Type: Articles    Category: .NET Framework
Author: Sadha SivamMember Level: Gold    
Rating: Points: 10



Recap of the previous sections of this
article

We saw about types, discussed about various types available and saw about structures.
In this section of article we will see how the structures can be implemented.
Defining a structure.
Defining a structure in .Net is as simple as declaring a variable.
Syntax for declaring a structure
 
Structure <STRUCTURE name>

…………………..

….……………….
'Member variables here

…………………..

…………………..

End Structure


It is very similar to declaring a class, we can do most the thing which are possible in classes such as they can have fields, properties, constants, events, methods, constructors and finalization code.
Rules governing the Structure definition
We should follow these rules strictly when defining a structure,

  • Structures must have at least one field or event declaration. (We cannot have a dummy structure block.)
    For eg.,
     
    'This structure definition is not allowed
    Structure DummyStructure


    End Structure

  • By default, structure will have a parameter-less constructor (as classes
    have). Which will be used for default initialization for variables. We cannot
    define a parameter-less constructor, but we can define a parameterized
    constructors.

  • Initialization of variables other than constants is not allowed, but they
    can be done using the parameterized constructors.

    For eg.,
     

    Structure ExampleStructure

    'Public intMem as Integer = 10 not allowed
    Public intMem as Integer
    Public Const intConst as Integer = 10 ' This is allowed

    Public Sub New(byval value as Integer) 'Parameterized constructor
    IntMem = value
    End Sub
    End Structure

  • Structure objects are deallocated when they go out of scope gather that
    being garbage-collected.

  • We should avoid defining Structures with public fields. (It is not the
    rule that structures cannot have public members) Public data is faster to
    access because it avoids the overhead of method calls to get at the data, but
    it clearly breaks the encapsulation of the structure.

  • .Net doesn't allows the class or structures to inherit from a
    structure.

Now, we will see a small example in structure.
Now, I am going to built a structure which is going to store the file size.
 
Structure FileSize
Public FsinMB as integer
Public Sub New(byval value as integer)
FsinMB=value
End Sub
End
Structure

In the above example, I have declared the created the structure which will
store the File Size, and I have also defined a constructor which integer
parameter.



See all the Structure in VB.Net Part 1, Part II , Part III , Part IV,Part V


Please send your valuable feed back to sadhasivam1981@yahoo.com.

Visit http://sadhasivam.t35.com to know more about me.





Responses


No responses found. Be the first to respond and make money from revenue sharing program.

Feedbacks      
Popular Tags   What are tags ?   Search Tags  
(No tags found.)

Post Feedback


This is a strictly moderated forum. Only approved messages will appear in the site. Please use 'Spell Check' in Google toolbar before you submit.
You must Sign In to post a response.
Next Resource: Structure in VB.Net - Part I
Previous Resource: Structures in VB.Net - Part III (Structures with properties and methods)
Return to Discussion Resource Index
Post New Resource
Category: .NET Framework


Post resources and earn money!
 
Related Resources



dotNet Slackers   BizTalk Adaptors    Web Design


Contact Us    Privacy Policy    Terms Of Use