How to pass an arry to a method

R

RayAll

I have an array of one of my classes (Client[] myarray) ,I'd like to pass
this array to a static method of a class for further processing what dose
the calling Methods signature look like?

Something like this ??

Public Static bool Validate(ref Object pointerToArray)
{

}


Thanks fro your help
 
R

RayAll

the second one copies the array to another one (CallByValue) where the first
one is CallBy ref,the only thing that I'm not sure is that,I'm not sure if I
am correctly using Call by ref in Arrays...

Thanks
SB said:
How about:

public static bool Validate(Client[] clientArray)
{
}

HTH,
sb

RayAll said:
I have an array of one of my classes (Client[] myarray) ,I'd like to pass
this array to a static method of a class for further processing what dose
the calling Methods signature look like?

Something like this ??

Public Static bool Validate(ref Object pointerToArray)
{

}


Thanks fro your help
 
G

Guest

I'm not sure what you're trying to accomplish by passing the array by
reference. Arrays are immutable, for length at least. And whether you pass
the array by value, only the references are copy. In other words, the copy
is shallow, not deep. You can still access and modify the values referenced
in the array.

Bruce Johnson [C# MVP]
http://www.objectsharp.com/blogs/bruce

RayAll said:
the second one copies the array to another one (CallByValue) where the first
one is CallBy ref,the only thing that I'm not sure is that,I'm not sure if I
am correctly using Call by ref in Arrays...

Thanks
SB said:
How about:

public static bool Validate(Client[] clientArray)
{
}

HTH,
sb

RayAll said:
I have an array of one of my classes (Client[] myarray) ,I'd like to pass
this array to a static method of a class for further processing what dose
the calling Methods signature look like?

Something like this ??

Public Static bool Validate(ref Object pointerToArray)
{

}


Thanks fro your help
 
W

Willy Denoyette [MVP]

RayAll said:
the second one copies the array to another one (CallByValue) where the
first one is CallBy ref,the only thing that I'm not sure is that,I'm not
sure if I am correctly using Call by ref in Arrays...


That's not true, an array is a ref type, so in the first case you are
passing a copy of the reference variable, in the second case you are passing
the address of the reference variable, but you never pass a copy of the
array contents!

Willy.
 
R

RayAll

So you mean by using the second one I could have the array manipulated in
the method.(I think it's also doable by the first one) right? the different
is only how the array is passed
1) By reference?
OR
2) By a refrence to a reference pointerToArray (reference) -> myArray
(reference)

Thanks
 
W

Willy Denoyette [MVP]

RayAll said:
So you mean by using the second one I could have the array manipulated in
the method.(I think it's also doable by the first one) right? the
different is only how the array is passed
1) By reference?
OR
2) By a refrence to a reference pointerToArray (reference) -> myArray
(reference)

Both can be used to change the array contents, the second method in addition
has the possibility to change the reference to the array passed in by the
caller.

Willy.
 

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

Top