Passing array as parameter in C#

array-as-parameter
In this chapter you will learn:

  • How to passing array as parameter?
  • How to declare a method to accept array as argument?
  • How to pass array as parameter using C# programming?

An array can also be passed to method as argument or parameter. A method process the array and returns output. Passing array as parameter in C# is pretty easy as passing other value as parameter. Just create a function that accepts array as argument and then process them. The following demonstration will help you to understand how to pass array as argument in C# programming.




  • Programming Example of passing array as parameter in C#

    Output

    Enter number:      5
    Enter number:      3
    Enter number:      2
    Enter number:      1You entered:     5    3    2    1Add sum of all value is:       11
    __

    In the preceding example, we create an array and accept some integer value from the user at runtime. Then we passed array as argument to printarray(int[] newarray)  for printing and other calculation. It is same as other value passed as parameter to the function.

    Summary

    In this chapter you learned how to pass array as parameter to the function. In next chapter you will learn about some predefined array function in C#.

     

    More Examples

     


    Leave a Reply

    Your email address will not be published. Required fields are marked *