Skip to content

Instantly share code, notes, and snippets.

@jonwarghed
Created August 23, 2017 09:09
Show Gist options
  • Save jonwarghed/9eaee08053d821ca29a99d29c462f549 to your computer and use it in GitHub Desktop.
Save jonwarghed/9eaee08053d821ca29a99d29c462f549 to your computer and use it in GitHub Desktop.
What is this C# syntax called?
namespace Trine.CLI
{
class Program
{
static void Main()
{
new Crash
{
Inner = {Name = "what"}
};
}
}
public class InnerType {
public string Name { get; set; }
}
public class Crash
{
public InnerType Inner { get; set; }
}
}
@christofferEkblom
Copy link

wierd? its called "object initializer"

@harounhajem
Copy link

harounhajem commented Aug 23, 2017

namespace Trine.CLI
{
    class Program
    {
        static void Main(string[] args)
        {
            new Crash
            {
                InnerNew_Property = { Name = "what" }
            };
        }
    }
  public class InnerType
    {
        public string Name { get; set; }
    }

    public class Crash
    {

        private InnerType InnerNew_Field = new InnerType();

        public InnerType InnerNew_Property
        {
            get
            {
                return InnerNew_Field;
            }

            set
            {
                InnerNew_Field = value;
            }
        }
    }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment