Use [,][] as parameter

M

Macneed

hi i am a newbie of C#

can i use [,][] as a ref parameter?

like this

main...
{
int[,][] idata as [100][200][];

define... = new [10 or other]...


Calc(ref idata);


}


public static void Calc ( ref int[,][] inputdata )
{
....
}

i run this but has an error
can i use [,][] as parameter
if yes,
any step i miss?

THANK YOU SO MUCH
 
A

Alex Meleta

Hi Macneed,

M> i run this but has an error
Which error?

M> can i use [,][] as parameter
Yes

M> any step i miss?
Provide your code, please.

Coz that should work.

int[,][] idata = new int[1, 1][];
idata[0, 0] = new int[1] { 10 };
Calc(ref idata);

inputdata[0,0][0].ToString());

Kind Regards, Alex Meleta
[TechBlog] http://devkids.blogspot.com



M> hi i am a newbie of C#
M>
M> can i use [,][] as a ref parameter?
M>
M> like this
M>
M> main...
M> {
M> int[,][] idata as [100][200][];
M> define... = new [10 or other]...
M>
M> Calc(ref idata);
M>
M> }
M>
M> public static void Calc ( ref int[,][] inputdata )
M> {
M> ...
M> }
M> i run this but has an error
M> can i use [,][] as parameter
M> if yes,
M> any step i miss?
M> THANK YOU SO MUCH
M>
 
C

Christof Nordiek

Macneed said:
i run this but has an error


In addition to what Jon said: What is the error, and in wich line it occurs.

Also note: You can pass an array (and an array of array ...) by reference,
but make sure this, is what you want to do. An Array is a reference type,
and it's content can be changed, even if it is not passed as reference.

Christof
 
M

Macneed

Jon Skeet said:
hi i am a newbie of C#

can i use [,][] as a ref parameter?
Yes.

like this

That's not your actual code. Please post a short but complete example
which demonstrates the problem, as per
http://pobox.com/~skeet/csharp/complete.html.
(And when you mention that there's an error, it would be helpful to
say what it is.)

Jon

Thanks

static void Main(string[] args)
{
const int Method=100;

float[,][] SPay = new float[100, 100][];

for (int i = 0; i < 100; )
{
for (int j = 0; j < 100; )
{
SPay[i,j++] = new float[Method]; //[Method] is sth like
that
}
i++;
}

Calc(ref SPay);
}

public static void Calc(ref float[,][] pSPay)
{
for (int i = 0; i < 100; )
{
for (int j = 0; j < 100; )
{
for (int k = 0; k < 100; )
{
pSPay[i, j][k++] = 10;
}
j++;
}
i++;
}
}

sth like that
after run
the cmd screen go to the background
and two windows at the bottom of code screen
the left one show that
Locals
Name Value Type
+ pSPay {Dimensions:[100,100]} float[,][]
i 0 int
....


the right one is
Call Stack
xxx.exe!xxx.Program.Calc(ref float[,][]pSPay = {Dimensions:[100,100]}Line
1480
xxx.exe!xxx.Program.Main(string[] args = {Dimensions:[0]} Line 296 + 0xb
bytes

the windows message is type, not copy out,
so may be a little little different,

Thanks all
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Passing arrays as parameters 6
waveInOpen 64-bit 0
mismatch in events 1
Control.Invoke and ref parameter 7
ref parameters 4
using ref keyword performance 6
b-tree 11
Observation on object references 6

Top