I just found the following code and don't know why it is done this way. Risk for conflict?
using DiffTreeNode = EPiServer.Enterprise.Diff.TreeNode;
And then in the class it is used as usual.
Why would you do something like this?
I just found the following code and don't know why it is done this way. Risk for conflict?
using DiffTreeNode = EPiServer.Enterprise.Diff.TreeNode;
And then in the class it is used as usual.
Why would you do something like this?
That's a
using
directive (see here) rather than ausing
statement and very similar to something likeusing System.Text;
.A
using
statement allows you to automatically clean up stuff without mucking about withtry/catch/finally
blocks:The
using
directive imports a namespace so that you don't have to explicitly use the namespace to prefix all the types within it. Your particular variant basically creates an alias for theEPiServer.Enterprise.Diff.TreeNode
namespace so you can simply refer to it asDiffTreeNode
beyond that point. In other words, after the directive:the following two statements are equivalent:
and I know which I'd prefer to type in.
Now you may be asking why, if the directive can let you use the types within a namespace on their own, why do we not just do:
My bet would be, though I'll wait for the likes of Jon Skeet to confirm or deny this :-), that it's to cover the case where you have two or more namespaces with identically named types. That would allow: