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. String Array question..

String Array question..

Scheduled Pinned Locked Moved C#
questiondata-structureslounge
5 Posts 5 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.
  • P Offline
    P Offline
    ptr2void
    wrote on last edited by
    #1

    Can we have an string array and add strings elements to it at random points of time, without using a for loop??

    Som

    M N N 3 Replies Last reply
    0
    • P ptr2void

      Can we have an string array and add strings elements to it at random points of time, without using a for loop??

      Som

      M Offline
      M Offline
      mmikey7
      wrote on last edited by
      #2

      You can not add element to array. Array has fixed lenght. You can only change any element in array any time: myArray[0] = "hey bob!"; if you need to add element to array you need to create a new array(with more elements) and copy elements from old arrray to it together with you new elements. But this is pretty much what List does, so if you need to add elements to array often at runtime I would recommend you to use List which also has a method called ToArray which return current state of List as regular array. hth

      1 Reply Last reply
      0
      • P ptr2void

        Can we have an string array and add strings elements to it at random points of time, without using a for loop??

        Som

        N Offline
        N Offline
        Nouman Bhatti
        wrote on last edited by
        #3

        you can use arraylist for this purpose

        P 1 Reply Last reply
        0
        • N Nouman Bhatti

          you can use arraylist for this purpose

          P Offline
          P Offline
          pmarfleet
          wrote on last edited by
          #4

          Nouman Bhatti wrote:

          you can use arraylist for this purpose

          No one uses the ArrayList anymore. The generic types in C# 2.0 have rendered it obsolete. I suggest you check out the Generic List<>[^] type instead.

          Paul Marfleet "No, his mind is not for rent To any God or government" Tom Sawyer - Rush

          1 Reply Last reply
          0
          • P ptr2void

            Can we have an string array and add strings elements to it at random points of time, without using a for loop??

            Som

            N Offline
            N Offline
            N a v a n e e t h
            wrote on last edited by
            #5

            You can use generic List<string> class.

            All C# applications should call Application.Quit(); in the beginning to avoid any .NET problems.- Unclyclopedia How to use google | Ask smart questions

            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