how to return array from class property?
-
Hello, i m using vb.net (winforms) & i have written class called employee. & make object of employee on my form & accessing all the properties of emp like id, name,sal etc. i shuld access all the values...so i wrotee property for each like Public ReadOnly Property BasicSal() As Integer Get Return BS1 End Get it is good whn property values are less but as i wnt to access all salary info like HRA, Basic Sal....etc total 20 fields. So i decided to use Array....I fill all values in array in my employee class's function itself. Th problem is i wnt to access this array of all values on my forms.How to do it plz tell me. Thanks for any help in advance. --Regards priya
"The Difficult i can do it now... The Impossible will take a little longer."
-
Hello, i m using vb.net (winforms) & i have written class called employee. & make object of employee on my form & accessing all the properties of emp like id, name,sal etc. i shuld access all the values...so i wrotee property for each like Public ReadOnly Property BasicSal() As Integer Get Return BS1 End Get it is good whn property values are less but as i wnt to access all salary info like HRA, Basic Sal....etc total 20 fields. So i decided to use Array....I fill all values in array in my employee class's function itself. Th problem is i wnt to access this array of all values on my forms.How to do it plz tell me. Thanks for any help in advance. --Regards priya
"The Difficult i can do it now... The Impossible will take a little longer."
You can implement the property list using, for instance, a
SortedList
. See the following MSDN excerpt:Imports System
Imports System.Collections
Imports Microsoft.VisualBasicPublic Class SamplesSortedList
Public Shared Sub Main() ' Creates and initializes a new SortedList. Dim mySL As New SortedList() mySL.Add("one", "The") mySL.Add("two", "quick") mySL.Add("three", "brown") mySL.Add("four", "fox") ' Displays the SortedList. Console.WriteLine("The SortedList contains the following:") PrintKeysAndValues(mySL) End Sub Public Shared Sub PrintKeysAndValues(myList As SortedList) Console.WriteLine(ControlChars.Tab & "-KEY-" & ControlChars.Tab & \_ "-VALUE-") Dim i As Integer For i = 0 To myList.Count - 1 Console.WriteLine(ControlChars.Tab & "{0}:" & ControlChars.Tab & \_ "{1}", myList.GetKey(i), myList.GetByIndex(i)) Next i Console.WriteLine() End Sub
End Class
' This code produces the following output.
'
' The SortedList contains the following:
' -KEY- -VALUE-
' four: fox
' one: The
' three: brown
' two: quickHope that helps :)
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.