On 30 Sep., 22:19, "Andrus" <kobrule...@hot.eewrote:
I need to pass 9-element string array to method
I tried code below bot got a lot of compile errors.
How to fix ?
Andrus.
class Test
{
* * static void Main()
* * {
* * * * string stringarray[9];
* * * * stringarray[0] = "test";
* * * * PassArray( stringarray );
* * }
* * static void PassArray ( string p[9] ) {
* * * // must output test
* * * Console.WriteLine( p[0] );
* * * }
}
In addition to what Jon said, there are also some syntactical errors
in your code, it should look more like this:
class Test
{
static void Main()
{
string[] stringarray = new string[9];
stringarray[0] = "test";
PassArray( stringarray );
}
static void PassArray ( string[] p ) {
// must output test
Console.WriteLine( p[0] );
}
}
To declare an array you put square brackets behind the type, to
instantiate it you use "new type[no_of_elements]".
hth,
Kevin Wienhold