|
-
Jul 14th, 2011, 02:27 AM
#1
Thread Starter
Lively Member
One array instead of 3
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?
-
Jul 14th, 2011, 02:36 AM
#2
Re: One array instead of 3
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.
-
Jul 14th, 2011, 04:19 AM
#3
Thread Starter
Lively Member
Re: One array instead of 3
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.
-
Jul 14th, 2011, 04:32 AM
#4
Re: One array instead of 3
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
-
Jul 14th, 2011, 08:05 AM
#5
Thread Starter
Lively Member
Re: One array instead of 3
Thank you.
So, it's not very convinient in my case.. May be better to leave arrays.
-
Jul 14th, 2011, 08:46 AM
#6
Re: One array instead of 3
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.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|