这里的using 作用是什么?

xuhongxin8477 xuhongxin8477 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区

using System;
using System.IO;
using System.Text;

class Test
{
public static void Main()
{
string path = @"c:\temp\MyTest.txt";

// Delete the file if it exists.
if (!File.Exists(path))
{
// Create the file.
using (FileStream fs = File.Create(path))
{
Byte[] info = new UTF8Encoding(true).GetBytes("This is some text in the file.");

// Add some information to the file.
fs.Write(info, 0, info.Length);
}
}

// Open the stream and read it back.
using (FileStream fs = File.OpenRead(path))
{
byte[] b = new byte[1024];
UTF8Encoding temp = new UTF8Encoding(true);

while (fs.Read(b,0,b.Length) > 0)
{
Console.WriteLine(temp.GetString(b));
}
}
}
}
...全文

相关推荐

语言的 using statement 与资源释放

语言的 using statement 与资源释放! 值得下载看看!资源免费,大家分享!!

YnSky

【优化方案】(湖北专用)高中英语 Unit1 Section Ⅲ Learning about Language & Using Language精品课件 新人教版选修10

【优化方案】(湖北专用)高中英语 Unit1 Section Ⅲ Learning about Language & Using Language精品课件 新人教版选修10

超级源码阿

php变量作用域的深入解析

PHP 中的每个变量都有一个针对它的作用域,它是指可以在其中访问变量(从而访问它的值)的一个领域。对于初学者来说,变量的作用域是它们所驻留的页面。因此,如果你定义了 $var,页面余下部分就可以访问 $var,但是,其它页面一般不能访问它(除非使用特殊的变量)。因为包含文件像它们是原始(包含)脚本的一部分那样工作,所以在 include() 那一行之前定义的变量可供包含文件使用。此外,包含文件内定义的变量可供 include() 那一行之后的父(包含)脚本使用。当使用你自己定义的函数时,所有这些都将变得不那么明显。这些函数具有它们自己的作用域,这意味着在一个函数内使用的变量不能在其外部使用,在

weixin_38693419

SOA Design Using WebSphere Message Broker and WebSphere ESB

IBM SOA开发,使用Message Broker和webSphere ESB,是不可多得的redbook

izhangzhen

C#中using的三种用法

using 指令有两个用途: 允许在命名空间中使用类型,以便您不必限定在该命名空间中使用的类型。 为命名空间创建别名。 using 关键字还用来创建 using 语句  定义一个范围,将在此范围之外释放一个或多个对象。 请参见 using 语句。http://www.yaosansi.com/blog/article.asp?id=669 using namespace; using alias = type|namespace;  参数 Alias  您希望用来表示命名空间或类型的用户定义符号。然后,您就可以使用 alias 来表示命名空间名称。 Type  您想通过 alias 表示的类型

weixin_38706007
评论 9
收藏 已收藏
分享
返回顶部
xuhongxin8477
C# 111,129 成员 642,539 内容