65.9K
CodeProject is changing. Read more.
Home

C# equivalent of VB's With keyword

starIconstarIconstarIconstarIconemptyStarIcon

4.00/5 (1 vote)

Feb 15, 2012

CPOL
viewsIcon

5370

It's not realy an alternate - but I think it should be mentioned. Most time you have this kind of code during initialization. So why not use this:StatusProgressBar spb = new StatusProgressBar() { IsIndeterminate = false, Visibility = Visibility.Visible, ...

It's not realy an alternate - but I think it should be mentioned. Most time you have this kind of code during initialization. So why not use this:
StatusProgressBar spb = new StatusProgressBar() {
                 IsIndeterminate = false,
                 Visibility = Visibility.Visible,
                 Minimum = 0,
                 Maximum = 100,
                 Value = 50
            };
So if you only want to save typing during object creatio, this is the way to go. No performance penalty (no delegate, or extra variable instance needed).