问题描述
我想知道有什么用C#中的使用关键字,我是新来的吧..
当我们需要使用使用关键字..我GOOGLE了它,不能得到满意的答案。我还是想知道一些你从极客..
i want to know what is the use of "using" keyword in c#, i am new to it..when we need to use "using" keyword.. i googled it, could not be satisfied with answers. still i want to know some more from you Geeks..
感谢
推荐答案
两个用途:
-
使用的指令的,例如
using System;
using System.IO;
using WinForms = global::System.Windows.Forms;
using WinButton = WinForms::Button;
这些都是用来导入命名空间(或创建别名命名空间或类型)。这些走在文件的顶部,之前的任何声明。
These are used to import namespaces (or create aliases for namespaces or types). These go at the top of the file, before any declarations.
使用的语句的例如。
using (Stream input = File.OpenRead(filename))
{
...
}
这只能与实施的IDisposable
类型中使用,并且是一个try / finally块这就要求的Dispose $ C语法糖$ C> finally块。这用于简化的资源管理
This can only be used with types that implement IDisposable
, and is syntactic sugar for a try/finally block which calls Dispose
in the finally block. This is used to simplify resource management.
这篇关于使用&QUOT的;使用"关键字在C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!