Begginer: How do I Load values into an array using a For Loop?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • mvalor
    New Member
    • Nov 2008
    • 1

    Begginer: How do I Load values into an array using a For Loop?

    Can anyone tell me what would be the general staement in code to load values into an array using a For Loop?

    mvalor
  • vanc
    Recognized Expert New Member
    • Mar 2007
    • 211

    #2
    dummy code (C#)

    Code:
    for(int i=0;i<array.upperbounce;i++)
    array[i] = value;

    Comment

    • balabaster
      Recognized Expert Contributor
      • Mar 2007
      • 798

      #3
      There's an alternative to loading arrays using loops in .NET too:

      VB:
      Code:
      Dim MyArray() As String = {"String1", "String2", "String3", "String4"}
      C#
      Code:
      string MyArray() = {"String1", "String2", "String3", "String4"}
      That's just an FYI... if you're trying to load a large array, then using this feature likely isn't going to be any help...

      Just to round out the previous comment - you didn't mention if you're using c# or vb so just on the off chance you're using vb:

      VB:
      Code:
      Dim MyArray(NumberOfItems) As String
      For i = 0 To NumberOfItems
            MyArray(i) = NumberOfItems
      Next
      Of course... an array list is easier to use:

      VB:
      Code:
      Dim MyArray As New ArrayList
      For i = 0 To NumberOfItems
          MyArray.Add("Item" & i)
      Next
      C#:
      Code:
      ArrayList MyArray = new ArrayList;
      for(i = 0; i < NumberOfItems; i++)
         MyArray.Add("Item"& i);
      Hope that helps...

      Comment

      Working...