| | |
arrays passed to methods and keyword param
Please support our C# advertiser: Programming Forums - DaniWeb Sister Site
Thread Solved |
•
•
Join Date: May 2007
Posts: 266
Reputation:
Solved Threads: 3
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.
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.
•
•
Join Date: Jan 2006
Posts: 275
Reputation:
Solved Threads: 11
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).
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).
![]() |
Similar Threads
- Hey Just started new topic with arrays, and having some trouble please help (C++)
- Question on arrays & methods (Java)
- Modify arrays passed by reference (C++)
- Help with arrays (C++)
- returning arrays from functions (C++)
- Need help with recursion and arrays (C++)
- passing arrays in visual basic (Visual Basic 4 / 5 / 6)
Other Threads in the C# Forum
- Previous Thread: how to include an NUnit fixture with an assembly
- Next Thread: converting variables.
Views: 2166 | Replies: 1
| Thread Tools | Search this Thread |
Tag cloud for C#
.net access algorithm array barchart bitmap box button buttons c# chat check checkbox class client code color combobox control conversion csharp custom database datagridview dataset datetime degrees draganddrop drawing encryption enum excel file files form format forms ftp function gcd gdi+ httpwebrequest image index input install java label list listbox listener login mandelbrot math mouseclick mysql networking object operator oracle path photoshop picturebox post prime programming radians regex remote remoting resource richtextbox save saving serialization server sleep socket sql statistics stream string table tcp text textbox thread time timer treeview update usercontrol validation view visualstudio webbrowser windows winforms wpf xml





