Quote:
|
quote:uh? That isn't C# syntax?
|
In the old days it wasn't. In today's (or actually tomorrow's) 3.5 world it is (almost, see below).... ;)
var persons = new Person(Name = "Adam");
var is a new C# keyword for type inference. The compiler infers the type by looking at the right hand side of the assignment and then types the persons variable appropriately. It looks like weakly type JavaScript but it isn't. After this line, you won't be able to assign another object type to persons (other than a type inheriting from Person that is).
var persons = new Person(
Name = "Adam");
Almost correct. You are trying to use object initializers, but got the syntax wrong. You use () first to instantiate the object, then use {..} to initialize the properties:
var persons = new Person
(){Name = "Adam"};
Doug: this is just compiler magic that eventually results in:
var persons = new Person();
persons.Name = "Adam";
It allows you to set one or more properties without the need to create specialized constructors.
Nooree: does that fix the error you're getting?
Imar
---------------------------------------
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Everyone is unique, except for me.
Author of
ASP.NET 2.0 Instant Results and
Beginning Dreamweaver MX / MX 2004