S
Simon
I have problems with object initialization. I have tried the procedure
described on:
http://davidhayden.com/blog/dave/archive/2006/12/04/ObjectInitializationExpressions.aspx
class Test
{
public short testId;
public string testStr;
public short Id
{
get { return testId; }
set { testId = value; }
}
public string Name
{
get { return testStr; }
set { testStr = value; }
}
}
But when I try this:
Test test = new Test{Id = 1, Name = "Name"};
I get error "A new expression requires () or [] after type".
I would also like to do this:
List<Test> test =
new List<Test> {
{ Id = 1, Name="Name" },
};
But I get the same error - "A new expression requires () or [] after type".
This new feature should work in C# 3.0 and I am using VS 2005. What am I
missing?
Thank you
Simon
described on:
http://davidhayden.com/blog/dave/archive/2006/12/04/ObjectInitializationExpressions.aspx
class Test
{
public short testId;
public string testStr;
public short Id
{
get { return testId; }
set { testId = value; }
}
public string Name
{
get { return testStr; }
set { testStr = value; }
}
}
But when I try this:
Test test = new Test{Id = 1, Name = "Name"};
I get error "A new expression requires () or [] after type".
I would also like to do this:
List<Test> test =
new List<Test> {
{ Id = 1, Name="Name" },
};
But I get the same error - "A new expression requires () or [] after type".
This new feature should work in C# 3.0 and I am using VS 2005. What am I
missing?
Thank you
Simon