Learn how to pass multi dimensional array as parameter in C# programming.

It is very easy to pass multi dimensional array as parameter or argument in C# programming. You can just pass it as you pass integer variable to a function.
By: Steven Clark
 
Sept. 18, 2011 - PRLog -- Most of the beginners think that they can pass only single dimensional array as parameter in C# programming. But actually it is completely myth. In C#, you can pass n depth of array as parameter to a function and function will process the argument and shows desired output.

Passing multi dimensional array as parameter is too simple as passing simple integer value as a parameter. If you are not able to pass multi dimensional array as parameter or getting trouble or error, then you are at a good place. In this C# tutorial you will learn how to pass multi dimensional array as parameter in C# programming. You can also visit the following link for complete details of how to pass multi dimensional array as parameter in C#.

http://www.completecsharptutorial.com/basic/array.php

Programming example of passing multi dimensional array as parameter in C sharp programming:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace array_parameter
{
   class Program
   {
       public static void multi_array(int[,] num)
       {
           for (int j = 0; j < 3; j++)
           {
               for (int k = 0; k < 3; k++)
               {
                   Console.Write("\t"+num[j, k]);
               }
               Console.WriteLine("\n");
           }
       }
       static void Main(string[] args)
       {
           int[,] arr = new int[3, 3] {{1,2,3},{4,5,6},{7,8,9}};
           Program.multi_array(arr);
           Console.ReadLine();
         
       }
   }
}

Output:

1   2   3
4   5   6
7   8   9



Explanation:

In the preceding example, we just created a function multi_array(int[,] num) that takes a multi dimensional array as argument or parameter and then print the value of array. In Main() function we create an multi dimensional array arr[,] and then pass the array as parameter to multi_array() function.

Based on preceding examples, you can also write various different programs for better understanding about how to pass multi dimensional array as parameter. You can also visit the following link for do the exercises. Here is great range of programming examples and exercises are available that will help you to understand array as well as other C# statements very well.

http://www.completecsharptutorial.com

# # #

Steven Clark is currently working in softsolution Private Limited, California at the post of senior software engineer since last 8 years. He has great experience in various .net products as C# 2.0, 3.5, XML, ASP.net, C#.net, WPF, XAML, Windows based application and web based application like HTML, Javascript, CSS, AJAX etc. He has also developed various enterprise edition web based application and being conducted in large projects. Since few days, he started to share his experience in C# programming via articles and blogs.
End
Source:Steven Clark
Email:***@gmail.com Email Verified
Tags:C sharp array programming
Industry:C# Programming, Education
Location:California City - California - United States
Account Email Address Verified     Account Phone Number Verified     Disclaimer     Report Abuse
Csharp Tutorial News
Trending
Most Viewed
Daily News



Like PRLog?
9K2K1K
Click to Share