简体   繁体   English

C#'使用'语句有什么用?

[英]What is this use of C# 'using' statement?

What is this use of c# using statement? c#using语句有什么用?

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. 根据MSDN使用声明有两个用法。

  1. (directive) Import types into current files, either directly or by giving an alias (指令)直接或通过给别名将类型导入当前文件
  2. (statement) Ensure IDisposable objects are properly disposed. (声明)确保正确处理IDisposable对象。

But in this case, it's used to assign a delegate type. 但在这种情况下,它用于分配委托类型。 Can anyone please explain this usage, and provide a link a documentation? 任何人都可以解释这种用法,并提供链接文档?

In this case the using statement is being used to alias a type, so yes point (1) you stated. 在这种情况下,using语句被用于别名类型,所以是你指出的点(1)。

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(/* ... */);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM