Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's this C# "using" directive?

I saw this C# using statement in a code example:

using StringFormat=System.Drawing.StringFormat;

What's that all about?

like image 615
Ronnie Overby Avatar asked Jun 23 '09 20:06

Ronnie Overby


People also ask

What C means?

abbreviation for Celsius: The temperature today reached 25°C.

What does C stand for in texting?

Summary of Key Points "Very Happy" is the most common definition for C: on Snapchat, WhatsApp, Facebook, Twitter, Instagram, and TikTok. C: Definition: Very Happy.

What does why C mean?

Wyd is a texting and internet acronym that stands for What (are) you doing? or What (would) you do?

What does C mean twitter?

“C” at the end of a tweet indicates that the tweet's content is copied from another source, commonly called copypasta. Sometimes, “c” is also used as a substitute for “see.” It can also be used as an emoji, representing a smiley face.


3 Answers

That's aliasing a typename to a shorter name. The same syntax can also be used for aliasing namespaces. See using directive.

(Updated in response to Richard)

like image 180
Sean Avatar answered Sep 25 '22 09:09

Sean


It's an alias, from now on, the user can use StringFormat to refer to System.Drawing.StringFormat. It's useful if you don't want to use the whole namespace (in case of name clash issues for example).

source: using Directive article from MSDN

like image 20
mbillard Avatar answered Sep 24 '22 09:09

mbillard


Perhaps a different, unrelated StringFormat is declared in another namespace like Acme.Stuff. If that were the case, this would cause confusion:

using System.Drawing; // Contains StringFormat type.
using Acme.Stuff;  // Contains another StringFormat type.

private void Foo()
{
    StringFormat myFormat = new StringFormat(); // which one to use?
}

Aliasing is with using on the StringFormat=System.Drawing.StringFormat clears up some of the confusion.

like image 31
Bullines Avatar answered Sep 25 '22 09:09

Bullines