Thread: Arrays

  1. #1
    Registered User
    Join Date
    Feb 2003
    Posts
    184

    Arrays

    Quick question about arrays.
    Is there any way to declare and initialize all elements of an array to one certain value without having to loop through the array.
    Ex.

    Code:
    string[] myarray = new string[10] {"a","a","a","a",.............}
    Instead of having to type every one, is there a way to initialize all elements to the same??????????????

    Thanks,
    Kendal

  2. #2
    Registered User
    Join Date
    Oct 2003
    Posts
    6
    nop

  3. #3
    Registered User
    Join Date
    Feb 2003
    Posts
    184
    Well that is no good then.

    Thanks for the reply,
    Kendal

  4. #4
    Registered User
    Join Date
    Oct 2003
    Posts
    6
    but you can write a static method to do that like:

    Code:
    public string [] init(string s, int len) {
        string [] result = new string[len];
        for (int i = 0; i < len; i++ ) result[i] = s;
        return result;
    }

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. pointers & arrays and realloc!
    By zesty in forum C Programming
    Replies: 14
    Last Post: 01-19-2008, 04:24 PM
  2. Replies: 16
    Last Post: 01-01-2008, 04:07 PM
  3. Need Help With 3 Parallel Arrays Selction Sort
    By slickwilly440 in forum C++ Programming
    Replies: 4
    Last Post: 11-19-2005, 10:47 PM
  4. Building B-Tree from Arrays
    By 0rion in forum C Programming
    Replies: 1
    Last Post: 04-09-2005, 02:34 AM
  5. Crazy memory problem with arrays
    By fusikon in forum C++ Programming
    Replies: 9
    Last Post: 01-15-2003, 09:24 PM