0

I find that it helps to download source code to see how things work. I did that with MVCForum, and when viewing the source code noticed a using statement as follows:

using MembershipCreateStatus = MVCForum.Domain.DomainModel.MembershipCreateStatus;

The MembershipCreateStatus is an enum and is used in different parts of the code as such.

if (createStatus != MembershipCreateStatus.Success)

Can someone explain why it would be done this way as I have never seen this before. Is it easier to do it this way rather than initialize the class?

*************Update*************

Thanks for the answers, sorry it was a duplicate but if I new about alias I would have search for that not "Using Statements"

I understand the use now.

tereško
  • 58,060
  • 25
  • 98
  • 150
George Phillipson
  • 830
  • 11
  • 39
  • As you said `MembershipCreateStatus` is a `enum`. Code size is reduced with that alias without reducing readability. What do you mean by "initialize the class"& – AndreySarafanov Jul 11 '14 at 10:59
  • In addition to the duplicate, [this question of mine](http://stackoverflow.com/questions/14141043/resolving-an-ambiguous-reference) was resolved using alias', it shows an example of real world application – Sayse Jul 11 '14 at 10:59

2 Answers2

1

It is not a using statement. It is a using directive which is completely different.

Soner Gönül
  • 97,193
  • 102
  • 206
  • 364
0

It's just a shortcut. It defines an "alias" for the long classname. You can use the alias instead of the long name and so it makes your code easier to read. That's all.

demoncodemonkey
  • 11,730
  • 10
  • 61
  • 103
  • But the alias has exactly the same name as the typename, so they could simply have imported the namespace – Dennis_E Jul 11 '14 at 10:59
  • @Dennis_E true, unless another type with exactly the same name exists in an already imported namespace. For example `log4net.ILog` vs `MyProject.ILog`. – demoncodemonkey Jul 11 '14 at 11:01