943,621 Members | Top Members by Rank

Ad:
  • C# Discussion Thread
  • Marked Solved
  • Views: 2669
  • C# RSS
Jul 11th, 2007
0

arrays passed to methods and keyword param

Expand Post »
i am very new to c# and dont understand all of array passing to methods. chief reason for these misunderstandings is the keyword param.

param can only be used in a method header once and is always passed by value. also it works on a number of individually declared variables which is then passed as an array.

But what then of a real variable array? the type declared by for example .... int[] a = new int[ 10 ];.....? Can one pass a real array to a method without the use of the keyword param? and is such an array passed by value or by reference. if the programmer can specify which one then how does he specify it? by typing in the keyword ref in front of the array? also can one pass more than one array. for example can one pass an integer array as well as a string array to a method? and lastly can one use the keyword out with an array.

sorry if these sound like silly questions. i was on a few websites but they did not answer the questions i just asked.
Similar Threads
Reputation Points: 160
Solved Threads: 3
Posting Whiz in Training
quintoncoert is offline Offline
266 posts
since May 2007
Jul 11th, 2007
0

Re: arrays passed to methods and keyword param

yes you can pass an array such as
MyMethod(byte[] jpgstream)
{
}

parameters are passed by value as a default so no need to specify byval. If you want to pass by reference then specify ref before EACH parameter that you want as a reference. There is also the OUT keyword in C# to specify out parameters (by val is and In parameter, by ref is an IN/OUT parameter and OUT is an Out parameter).
Reputation Points: 26
Solved Threads: 11
Posting Whiz in Training
f1 fan is offline Offline
275 posts
since Jan 2006

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C# Forum Timeline: how to include an NUnit fixture with an assembly
Next Thread in C# Forum Timeline: converting variables.





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC