Click here to Skip to main content
12,623,511 members (31,208 online)
Click here to Skip to main content
Alternatives (4)
Add your own
alternative version

Tagged as

Stats

87.7K views
21 bookmarked
Posted

C# equivalent of VB's With keyword

, 27 May 2011 CPOL
VB has a With keyword that you can use to save typing same variables name over and over again. Here's a similar workaround for C#

Alternatives

Members may post updates or alternatives to this current article in order to show different approaches or add new features.

27 May 2011
dzCepheus
You can limit the scope of 'p' inside your function:private void Whatever() { DoStuffHere(); // 'p' is not in scope. { var p = this.StatusProgressBar; // 'p' is in scope. p.IsIndeterminate = false; p.[etc] } // 'p' is not in...
27 May 2011
CaldasGSM
You are introducing a variable “p” in the local scope of the whole function :snot really.. you know you can use brackets anywhere inside the code to define subscopes, don't you:{var p = this.StatusProgressBar;p.IsIndeterminate = false;p.Visibility = Visibility.Visible;p.Minimum =...
15 Feb 2012
johannesnestler
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, ...
16 Feb 2012
Brightmoore Solutions LLC
This class wraps any Type to allow it to be used only within the context of a using statement. It allows for implicit casting to T so it is pretty transpartent.Example usage: using(string scoped_string = Scope("Hello, World!")) { ...

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author


| | Privacy | Terms of Use | Mobile
Web02 | 2.8.161128.1 | Last Updated 27 May 2011
Article Copyright 2011 by Omar Al Zabir
Everything else Copyright © CodeProject, 1999-2016
Layout: fixed | fluid