Home > Archive > C# > June 2004 > params with Arrays parameters
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
params with Arrays parameters
|
|
| JoseM 2004-06-24, 12:57 am |
| I have created 3 one demensional arrays and am trying to pass all
three to a method using the params key word. The issue is that I
can't retrieve the value for each of the arrays? I'm new to c# and
any suggestions would be greatly appreciated. My code snippet is
below
Thanks in advance for your suggestions.
// ========================================
=
// ========================================
=
using System;
namespace ParamArrayTest
{
public class Tester
{
static void Main()
{
Tester t = new Tester();
int [] explicitArray1 = new int[5] {1,2,3,4,5};
int [] explicitArray2 = new int[5] {6,7,8,9,10};
int [] explicitArray3 = new int[5] {11,12,13,14,15};
t. DisplayVal(explicitArray1,explicitArray2
, explicitArray3);
}
public virtual void DisplayVal(params Array[] intVals)
{
int objLength = intVals.Length;
//Console.WriteLine(objLength);
for(int i=0; i<objLength; i++)
{
foreach(int x in intVals[i])
{
Console.WriteLine("the value is: " + intVals[x]);
}
Console.WriteLine("******************");
}
}
}
}
| |
| Divak 2004-06-24, 12:57 am |
| Use the following DisplayVal method. I hope it is self explanatory
public virtual void DisplayVal(params Array[] intVals)
{
int objLength = intVals.Length;
//Console.WriteLine(objLength);
for(int i=0; i<objLength; i++)
{
Array temp=intVals[i];
for(int j=0;j<temp.Length;j++)
{
Console.WriteLine("the value is: " + temp.GetValue(j));
}
Console.WriteLine("******************");
}
}
Divak
jose_mendez22@hotmail.com (JoseM) wrote in message news:<d9290042.0406211323.447a92d7@posting.google.com>...
> I have created 3 one demensional arrays and am trying to pass all
> three to a method using the params key word. The issue is that I
> can't retrieve the value for each of the arrays? I'm new to c# and
> any suggestions would be greatly appreciated. My code snippet is
> below
>
> Thanks in advance for your suggestions.
>
> // ========================================
=
> // ========================================
=
>
> using System;
>
> namespace ParamArrayTest
> {
>
> public class Tester
> {
> static void Main()
> {
> Tester t = new Tester();
> int [] explicitArray1 = new int[5] {1,2,3,4,5};
> int [] explicitArray2 = new int[5] {6,7,8,9,10};
> int [] explicitArray3 = new int[5] {11,12,13,14,15};
> t. DisplayVal(explicitArray1,explicitArray2
, explicitArray3);
> }
>
>
> public virtual void DisplayVal(params Array[] intVals)
> {
> int objLength = intVals.Length;
> //Console.WriteLine(objLength);
>
> for(int i=0; i<objLength; i++)
> {
> foreach(int x in intVals[i])
> {
> Console.WriteLine("the value is: " + intVals[x]);
> }
> Console.WriteLine("******************");
> }
> }
>
>
> }
> }
|
|
|
|
|