Hi,
I heard in some webinar that it was possible to initialize several
properties using only the default ctor provided the properties had public
getters/setters. Something like:
Instead of this:
Person p = new Person;
p.Name = "Juan";
p.LastName = "Dent";
This:
Person p =new Person( Name = "Juan", LastName = "Dent");
I know i saw it, but how is this possible?

Signature
Thanks in advance,
Juan Dent, M.Sc.
Alex Blekhman - 26 Apr 2008 11:13 GMT
> I heard in some webinar that it was possible to initialize
> several properties using only the default ctor provided the
[quoted text clipped - 3 lines]
>
> I know i saw it, but how is this possible?
I think you're talking about object initialization:
"How to: Initialize Objects without Calling a Constructor"
http://msdn2.microsoft.com/en-us/library/bb397680.aspx
HTH
Alex
P.S. This group is dedicated to discussions about Visual Studio
IDE. It has nothing to do with C# programming language. You'll get
more relevant answers in the
"microsoft.public.dotnet.languages.csharp group".
Steven Cheng [MSFT] - 28 Apr 2008 03:55 GMT
Hi Juan,
As Alex mentioned, the properites initliazation syntax you mentioned is of
the C# 3.0 feature(in .NET 3.5):
#C# 3.0 Features: Object Initializers
http://weblogs.asp.net/dwahlin/archive/2007/09/09/c-3-0-features-object-init
ializers.aspx
#How to: Initialize Objects without Calling a Constructor (C# Programming
Guide)
http://msdn2.microsoft.com/en-us/library/bb397680.aspx
Sincerely,
Steven Cheng
Microsoft MSDN Online Support Lead
Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
msdnmg@microsoft.com.
==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
--------------------
>From: =?Utf-8?B?SnVhbiBEZW50?= <juandent@nospam.nospam>
>Subject: In VS2008 and C# 3.5, how can one use default ctors to set prop va
>Date: Fri, 25 Apr 2008 13:45:08 -0700
>Hi,
>
[quoted text clipped - 12 lines]
>
>I know i saw it, but how is this possible?