• Top Posts

    Arrays as arguments in C#


    •  An array is a collection of similar type variables which are referred to by a common   name.
    •  In C#, arrays are the reference types so it can be passed as arguments to the method.
    •  A method can modify the value of the elements of the array. 
    •  Both single dimensional and multidimensional arrays can be passed as an argument to the   methods
    1. .One can pass the 1-D arrays to a method.
    1.  There are various options like first, you declare and initialise the array separately then pass it the to the method. 
    1. Second, you can declare, initialise and pass the array to the method in a single line of code.

          Declare and initialise the array first and pass it to method  as an  argument 
          int[] arr={1,2,3,4,5};
          result(arr);
    • Declaring, initialising and passing the array to the method in a single line of code.


               Result(new int[] {1,2,3,4,5});

        

    No comments

    Post Top Ad

    ad728

    Post Bottom Ad

    ad728