Skip to content

Commit f0162a3

Browse files
author
Ron Petrusha
authored
Merge pull request #730 from dotnet/master
Update Live with current Master
2 parents 5912c61 + 1e5675b commit f0162a3

File tree

38 files changed

+715
-5
lines changed

38 files changed

+715
-5
lines changed

csharp/tutorials/patterns/finished/toll-calculator/Program.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ static void Main(string[] args)
3232
Console.WriteLine($"The toll for a three ride share is {tollCalc.CalculateToll(threeRideShare)}");
3333
Console.WriteLine($"The toll for a fullVan is {tollCalc.CalculateToll(fullVan)}");
3434

35-
Console.WriteLine($"The toll for an mepty taxi is {tollCalc.CalculateToll(emptyTaxi)}");
35+
Console.WriteLine($"The toll for an empty taxi is {tollCalc.CalculateToll(emptyTaxi)}");
3636
Console.WriteLine($"The toll for a single fare taxi is {tollCalc.CalculateToll(singleFare)}");
3737
Console.WriteLine($"The toll for a double fare taxi is {tollCalc.CalculateToll(doubleFare)}");
3838
Console.WriteLine($"The toll for a full van taxi is {tollCalc.CalculateToll(fullVanPool)}");
@@ -51,7 +51,7 @@ static void Main(string[] args)
5151
}
5252
catch (ArgumentException e)
5353
{
54-
Console.WriteLine("Caught an argument exception when using the wrong type", DayOfWeek.Friday);
54+
Console.WriteLine("Caught an argument exception when using the wrong type");
5555
}
5656
try
5757
{

csharp/tutorials/patterns/start/toll-calculator/Program.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ static void Main(string[] args)
2828
}
2929
catch (ArgumentException e)
3030
{
31-
Console.WriteLine("Caught an argument exception when using the wrong type", DayOfWeek.Friday);
31+
Console.WriteLine("Caught an argument exception when using the wrong type");
3232
}
3333
try
3434
{
@@ -64,7 +64,7 @@ static void Main(string[] args)
6464
Console.WriteLine($"The toll for a three ride share is {tollCalc.CalculateToll(threeRideShare)}");
6565
Console.WriteLine($"The toll for a fullVan is {tollCalc.CalculateToll(fullVan)}");
6666
67-
Console.WriteLine($"The toll for an mepty taxi is {tollCalc.CalculateToll(emptyTaxi)}");
67+
Console.WriteLine($"The toll for an empty taxi is {tollCalc.CalculateToll(emptyTaxi)}");
6868
Console.WriteLine($"The toll for a single fare taxi is {tollCalc.CalculateToll(singleFare)}");
6969
Console.WriteLine($"The toll for a double fare taxi is {tollCalc.CalculateToll(doubleFare)}");
7070
Console.WriteLine($"The toll for a full van taxi is {tollCalc.CalculateToll(fullVanPool)}");
@@ -83,7 +83,7 @@ static void Main(string[] args)
8383
}
8484
catch (ArgumentException e)
8585
{
86-
Console.WriteLine("Caught an argument exception when using the wrong type", DayOfWeek.Friday);
86+
Console.WriteLine("Caught an argument exception when using the wrong type");
8787
}
8888
try
8989
{
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
using System;
2+
using System.Diagnostics;
3+
4+
public class Example
5+
{
6+
public static void Main()
7+
{
8+
var p = new Process();
9+
p.StartInfo.UseShellExecute = false;
10+
p.StartInfo.RedirectStandardError = true;
11+
p.StartInfo.FileName = "Write500Lines.exe";
12+
p.Start();
13+
14+
// To avoid deadlocks, always read the output stream first and then wait.
15+
string output = p.StandardError.ReadToEnd();
16+
p.WaitForExit();
17+
18+
Console.WriteLine($"\nError stream: {output}");
19+
}
20+
}
21+
// The end of the output produced by the example includes the following:
22+
// Error stream:
23+
// Successfully wrote 500 lines.
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
using System;
2+
using System.Diagnostics;
3+
4+
public class Example
5+
{
6+
public static void Main()
7+
{
8+
var p = new Process();
9+
p.StartInfo.UseShellExecute = false;
10+
p.StartInfo.RedirectStandardOutput = true;
11+
string eOut = null;
12+
p.StartInfo.RedirectStandardError = true;
13+
p.ErrorDataReceived += new DataReceivedEventHandler((sender, e) =>
14+
{ eOut += e.Data; });
15+
p.StartInfo.FileName = "Write500Lines.exe";
16+
p.Start();
17+
18+
// To avoid deadlocks, use an asynchronous read operation on at least one of the streams.
19+
p.BeginErrorReadLine();
20+
string output = p.StandardOutput.ReadToEnd();
21+
p.WaitForExit();
22+
23+
Console.WriteLine($"The last 50 characters in the output stream are:\n'{output.Substring(output.Length - 50)}'");
24+
Console.WriteLine($"\nError stream: {eOut}");
25+
}
26+
}
27+
// The example displays the following output:
28+
// The last 50 characters in the output stream are:
29+
// ' 49,800.20%
30+
// Line 500 of 500 written: 49,900.20%
31+
// '
32+
//
33+
// Error stream: Successfully wrote 500 lines.
34+
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
using System;
2+
using System.Diagnostics;
3+
4+
public class Example
5+
{
6+
public static void Main()
7+
{
8+
var p = new Process();
9+
p.StartInfo.UseShellExecute = false;
10+
p.StartInfo.RedirectStandardOutput = true;
11+
p.StartInfo.FileName = "Write500Lines.exe";
12+
p.Start();
13+
14+
// To avoid deadlocks, always read the output stream first and then wait.
15+
string output = p.StandardOutput.ReadToEnd();
16+
p.WaitForExit();
17+
18+
Console.WriteLine($"The last 50 characters in the output stream are:\n'{output.Substring(output.Length - 50)}'");
19+
}
20+
}
21+
// The example displays the following output:
22+
// Successfully wrote 500 lines.
23+
//
24+
// The last 50 characters in the output stream are:
25+
// ' 49,800.20%
26+
// Line 500 of 500 written: 49,900.20%
27+
// '
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
using System;
2+
using System.IO;
3+
4+
public class Example
5+
{
6+
public static void Main()
7+
{
8+
for (int ctr = 0; ctr < 500; ctr++)
9+
Console.WriteLine($"Line {ctr + 1} of 500 written: {ctr + 1/500.0:P2}");
10+
11+
Console.Error.WriteLine("\nSuccessfully wrote 500 lines.\n");
12+
}
13+
}
14+
// The example displays the following output:
15+
// The last 50 characters in the output stream are:
16+
// ' 49,800.20%
17+
// Line 500 of 500 written: 49,900.20%
18+
//'
19+
//
20+
// Error stream: Successfully wrote 500 lines.
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Exe</OutputType>
5+
<TargetFramework>netcoreapp2.2</TargetFramework>
6+
<LangVersion>latest</LangVersion>
7+
</PropertyGroup>
8+
9+
</Project>
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
namespace AsyncBreakfast
2+
{
3+
internal class Bacon
4+
{
5+
}
6+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
namespace AsyncBreakfast
2+
{
3+
internal class Coffee
4+
{
5+
}
6+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
namespace AsyncBreakfast
2+
{
3+
internal class Egg
4+
{
5+
}
6+
}

0 commit comments

Comments
 (0)