The question is simple, but I want it to ask.
It's usually happend that I have some arrays with same length.
For example name(), surname(), age()
Is it the best way to leave all info in 3 arrays or it possible ( better ) to concatenate somehow?
Printable View
The question is simple, but I want it to ask.
It's usually happend that I have some arrays with same length.
For example name(), surname(), age()
Is it the best way to leave all info in 3 arrays or it possible ( better ) to concatenate somehow?
The most appropriate way is to use either an array (or a collection of class instances) or dataset.
vb Code:
Class Person Public Name As String Public Surname As String Public Age As Integer End Class Public a_persons() As Person ' Array Public l_persons As New List(Of Person) ' List Public d_persons As New Dictionary(Of String, Person) ' Keyed dictionary
Or use System.Data.Dataset or Datatable classes.
Ok.Thanks! Spasibo!
Public a_persons() As Person ' Array
That's I like.
But can't get idea why such a code throws error:
Dim persons(1) As person ' Array
Try
persons(0).Name = "Vasya"
persons(0).Name = "Vasin"
persons(0).Age = 21
MsgBox(persons(0).Name)
Catch
End Try
Will try to find some info to read.
When you define an array in this way, each entry is a class.
Code:Dim persons(1) As person ' Array
persons(0) = New person With {.Name = "Vasya", .Age = 21}
or
persons(1) = New person
persons(1).Name = "Vasin"
persons(1).Age = 22
Thank you.
So, it's not very convinient in my case.. May be better to leave arrays.
If you were to change the class to a structure, you do not have to instance it. However, classes are what OOP is all about, every button, every form, every string, every array are all classes.