In a namespace, we can also use an alias to refer to an existing namespace or some other type of data.
The use format for aliases is as follows:
The Using alias = an already existing type;
For example: using Soholife = System;
Here are a few examples to deepen our understanding:
Namespace N1. N2
{
Class A {}
}
Namespace N3
{
Using A = N1. N2. A
Class B:a {}
}
Here, in N3, A is the alias of N1.n2.a, and n3.b inherits from n1.n2.a! the same way we can get the same effect:
Namespace N3
{
Using R = N1. N2;
Class B:r.a {}
}
Here, I want to ask a question, first look at the following example:
Namespace N1. N2
{
Class A {}
}
Namespace N3
{
Class A {}
}
Namespace N3
{
Using A = N1. N2. A
}
If we write this, will there be a problem?
Of course the answer is yes, wrong! Because an alias must be the only one in the namespace, and because there is already
Class a{}, we are using a using a =n1.ne. A; So it must be a mistake! But if we should be:
Using B =n1. N2. A; Then what's the result? A friend of the door to think about it! I will not say more!
Originally thought can end, suddenly found that there is still a place has not said clearly, can say is not said, oh, it seems only late home, I door or from the question to see:
Namespace N1. N2
{
Class A {}
}
Namespace N3
{
Using R = N1. N2;
}
Namespace N3
{
Class B:r.a {}
}
In the above example, I do not know what you think, right? Error?
If I were to answer, wrong! (Oh, before the habit of making choice questions, the answer to this question is wrong!) But the reason is not to say it! )
Really above this program, first start to see I also thought is correct, later to know ... , alas, it seems to be more reading!
When using an alias in a separate cell, the alias is only available in the cell in which it is located (namespace or otherwise), but it is not sufficient in other cells, so in the example above, R is not known in the second N3. Of course, if we want to use this kind of way, we still have the way, is to write alias R to N3 outside: the following
Using R = N1. N2;
Namespace N3
{
Class B:r.a {}
}
Well said so much, if can all understand, I think should be appropriate to namespace have some concept! If so, my purpose is achieved!
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.