The forums have permanently moved to forum.kirupa.com. This forum will be kept around in read-only mode for archival purposes. To learn how to continue using your existing account on the new forums, check out this thread.


Results 1 to 8 of 8

Thread: passing arrays in C#

  1. #1

    passing arrays in C#

    How do I pass an array of any length in C#?

  2. #2
    into a method?

  3. #3
    a function, yes.

  4. #4
    Code:
            static void Main(string[] args)
            {
                int[] numb = new int[2];
                numb[0] = 3;
                numb[1] = 9;
    
                displayArray(numb);
    
                Console.WriteLine("Method Over");
                Console.ReadKey(true);
            }
    
            
    
            static void displayArray(int[] arrayParam)
            {
                for (int i = 0; i < arrayParam.Length; i++)
                {
                    Console.WriteLine(arrayParam[i]);
                }
            }
    This an example. That what you were after?

  5. #5
    jsauni, don't ya love it when you go through the effort to help and they don't even bother to say thanks!

  6. #6
    HAHA, well I feel much better now that someone's at least seen my answer.

  7. #7
    well, the biggest question is why dont you use like List<int>? to me it just seems more logical and easier to read. Then you can also pass it like a normal variable.

    public void fun (List<int> myList)

  8. #8
    Be careful of using generic when it isn't necessary. If you do not need to be able to add to the array a new element, or sort, etc then the overhead included with generics is meaningless, and so int[] is a better option. However, if the ability of sorting, adding, deleting of elements in the array is necessary, I agree a generic makes sense.

    The memory footprint isn't huge, but based on the size of the array, it could be.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

Home About kirupa.com Meet the Moderators Advertise

 Link to Us

 Credits

Copyright 1999 - 2012