Alias directive - What would it be?

Asked

Viewed 64 times

0

Good afternoon, everyone,

I’ve been studying C#, I came to see about the Directive using, and in the C# documentation it says it has 3 uses, one of the 3 use items says it serves to create an "alias" for a namespace or a type, but what would be an alias directive and what is its usefulness? I looked it up and couldn’t find out about.

1 answer

0


Serves to avoid ambiguity. Imagine the following situation:

using System.Windows.Forms;  
using System.Windows.Input;

In these two namespaces there are common classes. How would the compiler know which class you want? To solve this and still use the using you can create a nickname (alias):

using Input = System.Windows.Input; 

So you could access, for example: Input.ModifierKeysnot generating any ambiguity because he knows that Input refers to System.Windows.Input.

Some also believe it may be good practice, this I no longer know answer correctly.

This response was based on Zv_odd’s reply in https://stackoverflow.com/questions/505262/c-sharp-namespace-alias-whats-the-point (Soen)

Browser other questions tagged

You are not signed in. Login or sign up in order to post.