|
|
|
@ -5,18 +5,16 @@ public static class FSharpUsingPatterns
@@ -5,18 +5,16 @@ public static class FSharpUsingPatterns
|
|
|
|
|
{ |
|
|
|
|
public static void sample1() |
|
|
|
|
{ |
|
|
|
|
using (FileStream fs = File.Create("x.txt")) |
|
|
|
|
{ |
|
|
|
|
fs.WriteByte((byte)1); |
|
|
|
|
using (FileStream fileStream = File.Create("x.txt")) { |
|
|
|
|
fileStream.WriteByte((byte)1); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public static void sample2() |
|
|
|
|
{ |
|
|
|
|
Console.WriteLine("some text"); |
|
|
|
|
using (FileStream fs = File.Create("x.txt")) |
|
|
|
|
{ |
|
|
|
|
fs.WriteByte((byte)2); |
|
|
|
|
using (FileStream fileStream = File.Create("x.txt")) { |
|
|
|
|
fileStream.WriteByte((byte)2); |
|
|
|
|
Console.WriteLine("some text"); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
@ -24,9 +22,8 @@ public static class FSharpUsingPatterns
@@ -24,9 +22,8 @@ public static class FSharpUsingPatterns
|
|
|
|
|
public static void sample3() |
|
|
|
|
{ |
|
|
|
|
Console.WriteLine("some text"); |
|
|
|
|
using (FileStream fs = File.Create("x.txt")) |
|
|
|
|
{ |
|
|
|
|
fs.WriteByte((byte)3); |
|
|
|
|
using (FileStream fileStream = File.Create("x.txt")) { |
|
|
|
|
fileStream.WriteByte((byte)3); |
|
|
|
|
} |
|
|
|
|
Console.WriteLine("some text"); |
|
|
|
|
} |
|
|
|
@ -35,9 +32,8 @@ public static class FSharpUsingPatterns
@@ -35,9 +32,8 @@ public static class FSharpUsingPatterns
|
|
|
|
|
{ |
|
|
|
|
Console.WriteLine("some text"); |
|
|
|
|
int num; |
|
|
|
|
using (FileStream fs = File.OpenRead("x.txt")) |
|
|
|
|
{ |
|
|
|
|
num = fs.ReadByte(); |
|
|
|
|
using (FileStream fileStream = File.OpenRead("x.txt")) { |
|
|
|
|
num = fileStream.ReadByte(); |
|
|
|
|
} |
|
|
|
|
int firstByte = num; |
|
|
|
|
Console.WriteLine("read:" + firstByte.ToString()); |
|
|
|
@ -47,16 +43,14 @@ public static class FSharpUsingPatterns
@@ -47,16 +43,14 @@ public static class FSharpUsingPatterns
|
|
|
|
|
{ |
|
|
|
|
Console.WriteLine("some text"); |
|
|
|
|
int num; |
|
|
|
|
using (FileStream fs = File.OpenRead("x.txt")) |
|
|
|
|
{ |
|
|
|
|
num = fs.ReadByte(); |
|
|
|
|
using (FileStream fileStream = File.OpenRead("x.txt")) { |
|
|
|
|
num = fileStream.ReadByte(); |
|
|
|
|
} |
|
|
|
|
int firstByte = num; |
|
|
|
|
int num3; |
|
|
|
|
using (FileStream fs = File.OpenRead("x.txt")) |
|
|
|
|
{ |
|
|
|
|
int num2 = fs.ReadByte(); |
|
|
|
|
num3 = fs.ReadByte(); |
|
|
|
|
using (FileStream fileStream = File.OpenRead("x.txt")) { |
|
|
|
|
int num2 = fileStream.ReadByte(); |
|
|
|
|
num3 = fileStream.ReadByte(); |
|
|
|
|
} |
|
|
|
|
int secondByte = num3; |
|
|
|
|
Console.WriteLine("read: {0}, {1}", firstByte, secondByte); |
|
|
|
|