CodePaste Logo
New Snippet New Snippet Recent Snippets Recent Snippets My Snippets My Snippets Web Code Search Snippets Search
Sign inor Register
Language: C#

Object Initializer Syntax in C# 2008

295 Views
Copy Code Show/Hide Line Numbers
//without using Object Initializer Syntax
 
                    letter = new Letter();
                    letter.Date = DateTime.Now.Date;
                    letter.RegisterDate = DateTime.Now.Date;
                    letter.LetterType = LetterType.Outgoing;
 
                    letter.LetterInformation = new LetterInformation();
                    letter.LetterInformation.RuntimeState = common.RuntimeState.Added;
                    letter.LetterInformation.Letter = letter;
                    letter.LetterInformation.Attachments = new ArrayList();
                    letter.LetterInformation.FileName = new LetterInformationMedia();
                    letter.LetterInformation.FileName.RuntimeState = common.RuntimeState.Added;
                    letter.LetterInformation.FileName.LetterInformation = letter.LetterInformation;
                    letter.LetterInformation.FileName.FileName = new common.FilePath();
 
                    letter.RelatedLetters = new ArrayList();
 
                    letter.AllLetterMedia = new ArrayList();
 
                    letter.RuntimeState = Faraconesh.ApplicationFramework.Common.RuntimeState.Added;
 
////////////////////////////////////////////////////////////////////////////
 
//with using Object Initializer Syntax
 
                    letter = new Letter()
                    {
                        Date = DateTime.Now.Date,
                        RegisterDate = DateTime.Now.Date,
                        LetterType = LetterType.Outgoing,
                        Sec = OfficeAutomationUtility.GetCurrentSecretariat(),
 
                        RelatedLetters = new ArrayList(),
                        AllLetterMedia = new ArrayList(),
                        RuntimeState = Faraconesh.ApplicationFramework.Common.RuntimeState.Added,
 
                        LetterInformation = new LetterInformation()
                        {
                            RuntimeState = Faraconesh.ApplicationFramework.Common.RuntimeState.Added,
                            //Letter = letter,
                            Attachments = new ArrayList(),
                            FileName = new LetterInformationMedia()
                            {
                                RuntimeState = Faraconesh.ApplicationFramework.Common.RuntimeState.Added,
                                //LetterInformation = letter.LetterInformation,
                                FileName = new Faraconesh.ApplicationFramework.Common.FilePath()
                            }
                        }
                    };
 
                    //following lines can not be placed in the above initializer because of "Use of unassigned variable" error
                    letter.LetterInformation.Letter = letter;
                    letter.LetterInformation.FileName.LetterInformation = letter.LetterInformation;
by afsharm
  January 19, 2010 @ 4:17am
Tags:
Description:
Object Initializer Syntax: one of interesting C# 2008 language features that bring C# into the family of functional languages.

by afsharm    January 19, 2010 @ 4:28am

see this: http://en.wikipedia.org/wiki/Functional_programming

Add a comment


Report Abuse
brought to you by:
West Wind Techologies



If you find this site useful and use it frequently please consider making a donation to support this free service.
Donate