Skip to content
Discussion options

You must be logged in to vote

That would be a breaking change as an object initializer can already omit new in order to initialize an existing instance:

public class Person {
    public Address Address { get; set; } = new Address();
}

public class Address {
    public string Street { get; set; }
    public string State { get; set; }
}

public class C {
    public void M() {
        // initializes Person with a new instance of Address
        var person1 = new Person {
            Address = new() { // equiv to new Address()
                Street = "123 Main St.",
                State = "NY"
            }
        };
        
        // initializes Person using the existing instance of Address
        var person2 = new 

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@shawnshaddock
Comment options

Answer selected by 333fred
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants