Search code examples
c#vb6syntaxequivalent

What is the equivalent syntax in C#, if any?


Does C# have any equivalent for VB6

With 
End With

Solution

  • There's nothing quite equivalent, but C# 3 gained the ability to set properties on construction:

    var person = new Person { Name = "Jon", Age = 34 };
    

    And collections:

    var people = new List<Person>
    {
        new Person { Name = "Jon" },
        new Person { Name = "Holly"}
    };
    

    It's definitely not a replacement for all uses of With, but worth knowing for some of them.