Brap
Brap

Reputation: 2747

does 'using' provide any advantages?

When you reference certain methods, you can either use using or explicitly type in the entire namespace. Are there any speed advantages of using one method over the other, or is it simply there to make typing out the entire namespace easier? thanks

Upvotes: 3

Views: 428

Answers (3)

James Dunne
James Dunne

Reputation: 3677

Are we all forgetting about extension methods? They cannot be pulled into scope without a using namespace directive, as far as I know.

Upvotes: 0

Tomas Petricek
Tomas Petricek

Reputation: 243051

There is no difference at runtime.

In the .NET meta-data, a type is always represented using a full name that includes the namespace, so the using directive known from C# will disappear when a program is compiled.

There are some subtle aspects (at compile time) when it comes to writing the using inside or outside of a namespace (see for example this question), but that's also only a compile-time issue.

Upvotes: 6

Jon Hanna
Jon Hanna

Reputation: 113242

It's purely a syntactic matter and is compiled to the same thing. Take a look at the IL produced by each.

Upvotes: 3

Related Questions