Arrays

tesseract

Member
Joined
Jul 3, 2008
Messages
13
Programming Experience
3-5
This seems like a dumb question to me but i cant remember how to do this or even if i can

VB.NET:
RuleList.Add(New Rule("Pop Cap", 8, {25, 50, 75, 100, 125, 150, 175, 200}))
RuleList.Add(New Rule("Farm Count", 1, {"10"})

What i need to do is make a new Rule and they all have arrays of strings as the 3rd paramater and they will always be diffrent sizes and value, is there an easy way to do this?

here is a referance

VB.NET:
Public Sub New(ByVal _Name As String, ByVal _NumberOfFields As Integer,   ByVal DefaultValues() As String)
Name = _Name
NumberOfFields = _NumberOfFields
icon = New Bitmap("C:\Sphere.bmp")
isOpen = False
Values = DefaultValues
Loc = New Point(_X, _Y)
End Sub
 
When declaring a variable you can initialize it with that short form:
VB.NET:
Dim s() As String = {"10", "20"}
When passing a parameter you have to be more explicit by actually creating the object. Example call to method Sub test(ByVal x() As String)
VB.NET:
test(New String() {"10", "20"})
 
This seems like a dumb question to me but i cant remember how to do this or even if i can

VB.NET:
RuleList.Add(New Rule("Pop Cap", 8, {25, 50, 75, 100, 125, 150, 175, 200}))
RuleList.Add(New Rule("Farm Count", 1, {"10"})

I dont understand why you seem to pass the length of the array (8 in the first line seems to correspond to 8 array items)

The array has a .Length property that returns 8

RuleList.Add(New Rule("Pop Cap", New String() {"25", "50", "75", "100", "125", "150", "175", "200"}))
 
I dont understand why you seem to pass the length of the array (8 in the first line seems to correspond to 8 array items)

The array has a .Length property that returns 8

RuleList.Add(New Rule("Pop Cap", New String() {"25", "50", "75", "100", "125", "150", "175", "200"}))

I also have it save the length because later on in the code im using XML and still havent finished how im going to use everything or even if an array is the way to go, so i guess im saying it in case i change how i manage things that will still work
 
I'm not sure you understand: there is no need to pass the arraylength as a separate parameter because you can always ask an array how long it is

The only time we see lengths being passed is typically in conjunction with an offset if a subset of [an enumerable item] is to be used.
Consider: myString.SubString(1, 2) ' choose "BC" from "ABCDEF"
 
Back
Top