Equivalence of "With...End With" in C#?

odiseh picture odiseh · Jun 30, 2009 · Viewed 51.7k times · Source

I know that C# has the using keyword, but using disposes of the object automatically.

Is there the equivalence of With...End With in Visual Basic 6.0?

Answer

tomfanning picture tomfanning · Jun 30, 2009

It's not equivalent, but would this syntax work for you?

Animal a = new Animal()
{
    SpeciesName = "Lion",
    IsHairy = true,
    NumberOfLegs = 4
};