What is the C # 'using' statement?

What is the use of the 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, the use of the operator has two use cases.

  • (directive) Types of imports into current files either directly or by providing an alias
  • (statement) Make sure the IDisposable objects are positioned correctly.

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

+3


source to share


1 answer


In this case, the using statement is used for type aliases, so yes (1) you specified.

Later in the code, instead of typing:

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

      



You can write:

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

      

+16


source







All Articles