Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Populating and Viewing Arrays

Populating and Viewing Arrays

Scheduled Pinned Locked Moved C#
questiondata-structurestutorial
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • G Offline
    G Offline
    Gavin_Mannion
    wrote on last edited by
    #1

    Hi All, I am currently creating an application that needs to populate a number of arrays and then I need to be able to call them again in different parts of the application. At the moment I have figured out how to Populate an array if I know how many items I am going to have but how do popualte and array when I don't know how many items there are. And :) How do I find out how many items there are in an array once it is populated? This is what I have at the moment ==================== string[] ClinicNames; ClinicNames = new string[99]; int j = 0; while (dReader.Read()) { ClinicNames[j] = dReader.GetString(1); j = j + 1; } ====================

    P 1 Reply Last reply
    0
    • G Gavin_Mannion

      Hi All, I am currently creating an application that needs to populate a number of arrays and then I need to be able to call them again in different parts of the application. At the moment I have figured out how to Populate an array if I know how many items I am going to have but how do popualte and array when I don't know how many items there are. And :) How do I find out how many items there are in an array once it is populated? This is what I have at the moment ==================== string[] ClinicNames; ClinicNames = new string[99]; int j = 0; while (dReader.Read()) { ClinicNames[j] = dReader.GetString(1); j = j + 1; } ====================

      P Offline
      P Offline
      Peter Stephens
      wrote on last edited by
      #2

      To find the length of an array, use the Length property:

      String[] arr = new String[5];
      Console.WriteLine("The array length is {0}.", arr.Length);

      When you exceed the capacity of your array, you will have to allocate a new array and copy the contents of the old array to the new. You can automate this process by using the System.Collections.ArrayList class which will resize the array when necessary. -- Peter Stephens

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups