Skip to content

Commit 5c6e7bf

Browse files
Update snippets per issue. (#37793)
* Update snippets per issue. * Add project file. * Troubleshoot snippet build error. * Troubleshoot snippet error.
1 parent e5bd2e8 commit 5c6e7bf

File tree

3 files changed

+24
-15
lines changed

3 files changed

+24
-15
lines changed
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Exe</OutputType>
5+
<TargetFramework>net6.0</TargetFramework>
6+
<Nullable>enable</Nullable>
7+
<ImplicitUsings>enable</ImplicitUsings>
8+
<StartupObject>CompBuf</StartupObject>
9+
</PropertyGroup>
10+
11+
</Project>

samples/snippets/csharp/VS_Snippets_CLR_System/system.IO.StreamReader/CS/source2.cs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,8 @@ public static void Main()
1313
Console.WriteLine($"{FILE_NAME} does not exist!");
1414
return;
1515
}
16-
FileStream fsIn = new FileStream(FILE_NAME, FileMode.Open,
17-
FileAccess.Read, FileShare.Read);
18-
// Create an instance of StreamReader that can read
19-
// characters from the FileStream.
20-
using (StreamReader sr = new StreamReader(fsIn))
16+
// Create an instance of StreamReader characters from the file.
17+
using (StreamReader sr = new StreamReader(FILE_NAME))
2118
{
2219
string input;
2320
// While not at the end of the file, read lines from the file.

samples/snippets/csharp/VS_Snippets_CLR_System/system.IO.StreamReader/CS/source3.cs

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,19 @@ public static void Main()
1313
Console.WriteLine($"{FILE_NAME} does not exist.");
1414
return;
1515
}
16-
FileStream f = new FileStream(FILE_NAME, FileMode.Open,
17-
FileAccess.Read, FileShare.Read);
18-
// Create an instance of BinaryReader that can
19-
// read bytes from the FileStream.
20-
using (BinaryReader br = new BinaryReader(f))
16+
using (FileStream f = new FileStream(FILE_NAME, FileMode.Open, FileAccess.Read, FileShare.Read))
2117
{
22-
byte input;
23-
// While not at the end of the file, read lines from the file.
24-
while (br.PeekChar() > -1 )
18+
// Create an instance of BinaryReader that can
19+
// read bytes from the FileStream.
20+
using (BinaryReader br = new BinaryReader(f))
2521
{
26-
input = br.ReadByte();
27-
Console.WriteLine(input);
22+
byte input;
23+
// While not at the end of the file, read lines from the file.
24+
while (br.PeekChar() > -1)
25+
{
26+
input = br.ReadByte();
27+
Console.WriteLine(input);
28+
}
2829
}
2930
}
3031
}

0 commit comments

Comments
 (0)