Dear Visitore of this Question I m New to VB.net
i have declared a structure in vb.net and i want to give values to its members how could i can do that
help me plz

Structure Employee
dim inta as integer
dim strs as string
end structure

how to intialise the values to inta and strs

5 Years
Discussion Span
Last Post by firdousahmad

There are a few methods for Structures, but there is more support for Classes. The easiest is to just assign the elements one at a time.

Dim empTest As Employee

empTest.inta = 1
empTest.strs = "Bill White"

To create an initializer, you need to create a Sub New and pass the initialization to it. You also have to declare the variable using the New keyword.

Structure Employee
    Public inta As Integer
    Public strs As String

    Public Sub New(intNew as Integer, strNew As String)
        inta = intNew
        strs = strNew
    End Sub
End Structure

Dim empTest As Employee = New Employee(1, "Bill White")

If you are wanting this kind of construction, it might be time to start considering Classes instead.


it is so simple create an instance ot the structure and give the values to the instance
dim emp as employee

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.