With block equivalent in C#?


I know VB.Net and am trying to brush up on my C#. Is there a With block equivalent in C#?


3/2/2009 3:27:02 AM

Although C# doesn't have any direct equivalent for the general case, C# 3 gain object initializer syntax for constructor calls:

var foo = new Foo { Property1 = value1, Property2 = value2, etc };

See chapter 8 of C# in Depth for more details - you can download it for free from Manning's web site.

(Disclaimer - yes, it's in my interests to get the book into more people's hands. But hey, it's a free chapter which gives you more information on a related topic...)

1/26/2009 11:48:03 PM

Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow