Re: initializer for array of struct
- From: Jon Skeet [C# MVP] <skeet@xxxxxxxxx>
- Date: Fri, 27 May 2005 07:17:10 +0100
ChrisA <ChrisA@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote:
> I have an array of 'struct' with three string fields which I would like to
> initialize.
> Is this possible?
>
> public struct Role
> {
> string a; string b; string c;
> }
> ...
> Role[] roles = ?? ( {"1","2","3"}, {"4","5","6"} };
Not quite, no. You'd need:
public struct Role
{
string a, b, c;
public Role (string a, string b, string c)
{
this.a = a;
this.b = b;
this.c = c;
}
}
then
Role[] roles = new Role[] { new Role ("1", "2", "3"),
new Role ("4", "5", "6") };
--
Jon Skeet - <skeet@xxxxxxxxx>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
.
- Follow-Ups:
- Re: initializer for array of struct
- From: ChrisA
- Re: initializer for array of struct
- References:
- initializer for array of struct
- From: ChrisA
- initializer for array of struct
- Prev by Date: Re: what's the point of an interface?
- Next by Date: Re: Finding server with broadcast
- Previous by thread: initializer for array of struct
- Next by thread: Re: initializer for array of struct
- Index(es):
Relevant Pages
|