您的位置:首页 > 其它

浅谈Try catch finally 与using

2010-01-17 22:23 399 查看
对于Try catch finally,大家应该都不陌生,您接触的写法可能会是下面的记几种类型:

Try catch (您可以匹配多个catch)

try

{

}

catch (Exception)

{

throw;

}

Try finally

try

{

}

finally

{

}

Try catch finally (同样,你一样可以匹配多个catch)

usingTry<?xml version="1.0" encoding="utf-8" ?>
<CodeSnippets xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
<CodeSnippet Format="1.0.0">
<Header>
<Title>usingTry</Title>
<Shortcut>usingTry</Shortcut>
<Description>Code snippet for using statement add Try</Description>
<Author>Microsoft Corporation</Author>
<SnippetTypes>
<SnippetType>Expansion</SnippetType>
<SnippetType>SurroundsWith</SnippetType>
</SnippetTypes>
</Header>
<Snippet>
<Declarations>
<Literal>
<ID>resource</ID>
<ToolTip>Resource to use</ToolTip>
<Default>resource</Default>
</Literal>
<Literal>
<ID>expression</ID>
<ToolTip>Exception type</ToolTip>
<Function>SimpleTypeName(global::System.Exception)</Function>
</Literal>
</Declarations>
<Code Language="csharp"><![CDATA[
using($resource$)
{
try
{
$selected$
}
catch ($expression$)
{
$end$
}
}]]>
</Code>
</Snippet>
</CodeSnippet>
</CodeSnippets>

至此,完成了一个加强版的using,和使用普通的using是一样的。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: