Search code examples
c#keywordusing

What is this use of C# 'using' statement?


What is this use of c# using statement?

namespace Microsoft.Owin.Host.SystemWeb.DataProtection {
    using DataProtectionProviderDelegate = Func<string[], Tuple<Func<byte[], byte[]>, Func<byte[], byte[]>>>;
    using DataProtectionTuple = Tuple<Func<byte[], byte[]>, Func<byte[], byte[]>>;

Taken from here

According to MSDN using statement has two usages.

  1. (directive) Import types into current files, either directly or by giving an alias
  2. (statement) Ensure IDisposable objects are properly disposed.

But in this case, it's used to assign a delegate type. Can anyone please explain this usage, and provide a link a documentation?


Solution

  • In this case the using statement is being used to alias a type, so yes point (1) you stated.

    Later on in code rather than having to type:

    var x = new  Tuple<Func<byte[], byte[]>, Func<byte[], byte[]>>(/* ... */);
    

    You can write:

    var x = new DataProtectionTuple(/* ... */);