diff --git a/samples/snippets/csharp/VS_Snippets_CLR_System/system.IO.StreamReader/CS/compose.csproj b/samples/snippets/csharp/VS_Snippets_CLR_System/system.IO.StreamReader/CS/compose.csproj new file mode 100644 index 0000000000000..653a462733c0e --- /dev/null +++ b/samples/snippets/csharp/VS_Snippets_CLR_System/system.IO.StreamReader/CS/compose.csproj @@ -0,0 +1,11 @@ + + + + Exe + net6.0 + enable + enable + CompBuf + + + \ No newline at end of file diff --git a/samples/snippets/csharp/VS_Snippets_CLR_System/system.IO.StreamReader/CS/source2.cs b/samples/snippets/csharp/VS_Snippets_CLR_System/system.IO.StreamReader/CS/source2.cs index 5fe7a2b67ff74..d614837210269 100644 --- a/samples/snippets/csharp/VS_Snippets_CLR_System/system.IO.StreamReader/CS/source2.cs +++ b/samples/snippets/csharp/VS_Snippets_CLR_System/system.IO.StreamReader/CS/source2.cs @@ -13,11 +13,8 @@ public static void Main() Console.WriteLine($"{FILE_NAME} does not exist!"); return; } - FileStream fsIn = new FileStream(FILE_NAME, FileMode.Open, - FileAccess.Read, FileShare.Read); - // Create an instance of StreamReader that can read - // characters from the FileStream. - using (StreamReader sr = new StreamReader(fsIn)) + // Create an instance of StreamReader characters from the file. + using (StreamReader sr = new StreamReader(FILE_NAME)) { string input; // While not at the end of the file, read lines from the file. diff --git a/samples/snippets/csharp/VS_Snippets_CLR_System/system.IO.StreamReader/CS/source3.cs b/samples/snippets/csharp/VS_Snippets_CLR_System/system.IO.StreamReader/CS/source3.cs index 1ed6500a096ac..47d86a8952593 100644 --- a/samples/snippets/csharp/VS_Snippets_CLR_System/system.IO.StreamReader/CS/source3.cs +++ b/samples/snippets/csharp/VS_Snippets_CLR_System/system.IO.StreamReader/CS/source3.cs @@ -13,18 +13,19 @@ public static void Main() Console.WriteLine($"{FILE_NAME} does not exist."); return; } - FileStream f = new FileStream(FILE_NAME, FileMode.Open, - FileAccess.Read, FileShare.Read); - // Create an instance of BinaryReader that can - // read bytes from the FileStream. - using (BinaryReader br = new BinaryReader(f)) + using (FileStream f = new FileStream(FILE_NAME, FileMode.Open, FileAccess.Read, FileShare.Read)) { - byte input; - // While not at the end of the file, read lines from the file. - while (br.PeekChar() > -1 ) + // Create an instance of BinaryReader that can + // read bytes from the FileStream. + using (BinaryReader br = new BinaryReader(f)) { - input = br.ReadByte(); - Console.WriteLine(input); + byte input; + // While not at the end of the file, read lines from the file. + while (br.PeekChar() > -1) + { + input = br.ReadByte(); + Console.WriteLine(input); + } } } }