C# inner object’s touch notation.

The notation will not create or change the internal object.

That's it

var obj = new Obj
       {
              Inner = {CompanyName = "Any name"}
       };

Required that the inner object was created before of use.

The full example:

       class Program
       {

             static void Main()
             {
                    var obj = new Obj
                           {
                                  Inner = {CompanyName = "Any name"}
                           };
             }


       }

       class Obj
       {
             private InnerObj _inner = new InnerObj();
             public InnerObj Inner
             {
                    get
                    {
                           return _inner;
                    }
                    set
                    {
                           _inner = value;
                    }
             }
       }

       class InnerObj
       {
             private string _companyName;
             public String CompanyName
             {
                    get
                    {
                           return _companyName;
                    }
                    set
                    {
                           _companyName = value;
                    }
             }
       }

Comments

Popular posts from this blog

Convention over Git = CoG

jQuery Deferred Object method chain or a Syntactic Sugar

Ctrl+Shift+Right arrow doesn't work in Visual Studio 2019