Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Visual Studio.NET / IDE / April 2008

Tip: Looking for answers? Try searching our database.

In VS2008 and C# 3.5, how can one use default ctors to set prop va

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Juan Dent - 25 Apr 2008 21:45 GMT
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?

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.