~mkw

Average guy, above average luck...the blog of M. Keith Warren

C# - using keyword

Most devs I work with are shocked to learn that the using keyword in the C# language is diatic. The obvious is for namespace inclusion but the less often seen use is for aliasing. For example, I hate having to reference the static members of ConfigurationSettings via the fully qualified name of System.Configuration.ConfigurationSettings. This is where aliasing can be cool; just give the class an alias with the using keyword like this:

  using cfg = System.Configuration.ConfigurationSettings;

This will allow you to refer to the members of System.Configuration.ConfigurationSettings using the cfg alias name.

Comments

Marc LaFleur said:

Wow. Very cool tip.
# August 12, 2003 11:01 PM

TrackBack said:

# August 13, 2003 7:46 AM

Stan said:

What does 'diatic' mean?

Before I displayed my ignorance, I checked with Merriam-Webster. The assistent editor who answered me thought you might mean 'dyadic'. It doesn't detract much from your point, but it bugs the bejeesus out of me not knowing.

- Stan

------------------
"You keep using that word. I do not think it means what you think it means." - Inigo Montoya
# March 25, 2004 7:50 PM

M. Keith Warren said:

Diatic is a term often associated with the phrase Dual Use
# March 25, 2004 8:30 PM

Gigi said:

Actually, using is triatic (now, what does that mean?). It can be used to to wrap a disposable (implements IDisposable) object in a scope so that the Dispose() method is called automatically when exiting the scope. It is similar to C++ destruction of automatic objects and is very cool when waiting for finalization is not an option and you don't want to remember calling dispose() all over the place.
# April 20, 2004 5:14 AM

Yousf said:

NOTE: The scope of this keyword is only file scope.

It is not *actual* replacement of the C typedef keyword.

# July 20, 2008 8:20 AM

typedef in c#? | keyongtech said:

Pingback from  typedef in c#? | keyongtech

# January 22, 2009 5:13 AM
Leave a Comment

(required) 

(required) 

(optional)

(required)