0
|
1 using System;
|
|
2 using NUnit.Framework;
|
|
3 using BLToolkit.Data;
|
|
4
|
|
5 namespace HowTo.Data
|
|
6 {
|
|
7 [TestFixture]
|
|
8 public class Close
|
|
9 {
|
|
10 [Test]
|
|
11 public void Test1()
|
|
12 {
|
|
13 var db = new DbManager();
|
|
14
|
|
15 /*[a]*/try/*[/a]*/
|
|
16 {
|
|
17 // ...
|
|
18 }
|
|
19 /*[a]*/finally/*[/a]*/
|
|
20 {
|
|
21 if (db != null)
|
|
22 db./*[a]*/Close/*[/a]*/();
|
|
23 }
|
|
24 }
|
|
25
|
|
26 // Consider using the C# [b][i]using[/i][/b] statement instead.
|
|
27 //
|
|
28 [Test]
|
|
29 public void Test2()
|
|
30 {
|
|
31 /*[a]*/using (var db = new DbManager())/*[/a]*/
|
|
32 {
|
|
33 // ...
|
|
34 }
|
|
35 }
|
|
36 }
|
|
37 }
|