Re: Arrays as parameters
Stuart Dunkeld <[email protected]> Sat, 21 Jun 2008 22:15:15 +0100
| Newsgroups | gmane.comp.windows.devel.dotnet.winforms |
|---|---|
| Message-ID | <[email protected]> |
This will work: you need to know how big you want the array to be
though: if you can't tell in advance, you could use a method which
will redimension the array as necessary and add the new item.
List<string> makes this a bit easier. Note there is no set{} required
in the MyArray property.
static class Program
{
static void Main()
{
Someclass sc = new Someclass();
sc.MyArray[0] = "This is test 1";
sc.MyArray[1] = "Thisis test 2";
}
}
class Someclass
{
string[] myarray = new string[2];
public string[] MyArray
{
get { return myarray; }
}
}
Regards
Stuart
On Mon, Jun 16, 2008 at 8:17 PM, Steve Abaffy <[email protected]> wrote:
> Hello,
>
> How does one do the following:
>
> Class Someclass{
>
> Private string [] myarray;
>
> Public string [] MyArray {get { return myarray[];} set{myarray[]=
> value;}}
> }
> Correctly? I want to be able to declare this class in my main function and
> set the parameters of the myarray as
>
> Someclass Sc = new someclass;
> Sc.MyArray[0] = "This is test 1";
> Sc.MyArray[1] = "Thisis test 2";
> Etc...
>
> Thanks
>