Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ static void Main(string[] args)
Console.WriteLine($"The toll for a three ride share is {tollCalc.CalculateToll(threeRideShare)}");
Console.WriteLine($"The toll for a fullVan is {tollCalc.CalculateToll(fullVan)}");

Console.WriteLine($"The toll for an mepty taxi is {tollCalc.CalculateToll(emptyTaxi)}");
Console.WriteLine($"The toll for an empty taxi is {tollCalc.CalculateToll(emptyTaxi)}");
Console.WriteLine($"The toll for a single fare taxi is {tollCalc.CalculateToll(singleFare)}");
Console.WriteLine($"The toll for a double fare taxi is {tollCalc.CalculateToll(doubleFare)}");
Console.WriteLine($"The toll for a full van taxi is {tollCalc.CalculateToll(fullVanPool)}");
Expand All @@ -51,7 +51,7 @@ static void Main(string[] args)
}
catch (ArgumentException e)
{
Console.WriteLine("Caught an argument exception when using the wrong type", DayOfWeek.Friday);
Console.WriteLine("Caught an argument exception when using the wrong type");
}
try
{
Expand Down
6 changes: 3 additions & 3 deletions csharp/tutorials/patterns/start/toll-calculator/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ static void Main(string[] args)
}
catch (ArgumentException e)
{
Console.WriteLine("Caught an argument exception when using the wrong type", DayOfWeek.Friday);
Console.WriteLine("Caught an argument exception when using the wrong type");
}
try
{
Expand Down Expand Up @@ -64,7 +64,7 @@ static void Main(string[] args)
Console.WriteLine($"The toll for a three ride share is {tollCalc.CalculateToll(threeRideShare)}");
Console.WriteLine($"The toll for a fullVan is {tollCalc.CalculateToll(fullVan)}");

Console.WriteLine($"The toll for an mepty taxi is {tollCalc.CalculateToll(emptyTaxi)}");
Console.WriteLine($"The toll for an empty taxi is {tollCalc.CalculateToll(emptyTaxi)}");
Console.WriteLine($"The toll for a single fare taxi is {tollCalc.CalculateToll(singleFare)}");
Console.WriteLine($"The toll for a double fare taxi is {tollCalc.CalculateToll(doubleFare)}");
Console.WriteLine($"The toll for a full van taxi is {tollCalc.CalculateToll(fullVanPool)}");
Expand All @@ -83,7 +83,7 @@ static void Main(string[] args)
}
catch (ArgumentException e)
{
Console.WriteLine("Caught an argument exception when using the wrong type", DayOfWeek.Friday);
Console.WriteLine("Caught an argument exception when using the wrong type");
}
try
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
using System;
using System.Diagnostics;

public class Example
{
public static void Main()
{
var p = new Process();
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardError = true;
p.StartInfo.FileName = "Write500Lines.exe";
p.Start();

// To avoid deadlocks, always read the output stream first and then wait.
string output = p.StandardError.ReadToEnd();
p.WaitForExit();

Console.WriteLine($"\nError stream: {output}");
}
}
// The end of the output produced by the example includes the following:
// Error stream:
// Successfully wrote 500 lines.
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
using System;
using System.Diagnostics;

public class Example
{
public static void Main()
{
var p = new Process();
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardOutput = true;
string eOut = null;
p.StartInfo.RedirectStandardError = true;
p.ErrorDataReceived += new DataReceivedEventHandler((sender, e) =>
{ eOut += e.Data; });
p.StartInfo.FileName = "Write500Lines.exe";
p.Start();

// To avoid deadlocks, use an asynchronous read operation on at least one of the streams.
p.BeginErrorReadLine();
string output = p.StandardOutput.ReadToEnd();
p.WaitForExit();

Console.WriteLine($"The last 50 characters in the output stream are:\n'{output.Substring(output.Length - 50)}'");
Console.WriteLine($"\nError stream: {eOut}");
}
}
// The example displays the following output:
// The last 50 characters in the output stream are:
// ' 49,800.20%
// Line 500 of 500 written: 49,900.20%
// '
//
// Error stream: Successfully wrote 500 lines.

Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
using System;
using System.Diagnostics;

public class Example
{
public static void Main()
{
var p = new Process();
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.FileName = "Write500Lines.exe";
p.Start();

// To avoid deadlocks, always read the output stream first and then wait.
string output = p.StandardOutput.ReadToEnd();
p.WaitForExit();

Console.WriteLine($"The last 50 characters in the output stream are:\n'{output.Substring(output.Length - 50)}'");
}
}
// The example displays the following output:
// Successfully wrote 500 lines.
//
// The last 50 characters in the output stream are:
// ' 49,800.20%
// Line 500 of 500 written: 49,900.20%
// '
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
using System;
using System.IO;

public class Example
{
public static void Main()
{
for (int ctr = 0; ctr < 500; ctr++)
Console.WriteLine($"Line {ctr + 1} of 500 written: {ctr + 1/500.0:P2}");

Console.Error.WriteLine("\nSuccessfully wrote 500 lines.\n");
}
}
// The example displays the following output:
// The last 50 characters in the output stream are:
// ' 49,800.20%
// Line 500 of 500 written: 49,900.20%
//'
//
// Error stream: Successfully wrote 500 lines.
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp2.2</TargetFramework>
<LangVersion>latest</LangVersion>
</PropertyGroup>

</Project>
6 changes: 6 additions & 0 deletions snippets/csharp/tour-of-async/AsyncBreakfast-V2/Bacon.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
namespace AsyncBreakfast
{
internal class Bacon
{
}
}
6 changes: 6 additions & 0 deletions snippets/csharp/tour-of-async/AsyncBreakfast-V2/Coffee.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
namespace AsyncBreakfast
{
internal class Coffee
{
}
}
6 changes: 6 additions & 0 deletions snippets/csharp/tour-of-async/AsyncBreakfast-V2/Egg.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
namespace AsyncBreakfast
{
internal class Egg
{
}
}
6 changes: 6 additions & 0 deletions snippets/csharp/tour-of-async/AsyncBreakfast-V2/Juice.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
namespace AsyncBreakfast
{
internal class Juice
{
}
}
78 changes: 78 additions & 0 deletions snippets/csharp/tour-of-async/AsyncBreakfast-V2/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
using System;
using System.Threading.Tasks;

namespace AsyncBreakfast
{
class Program
{
// <SnippetMain>
static async Task Main(string[] args)
{
Coffee cup = PourCoffee();
Console.WriteLine("coffee is ready");
Egg eggs = await FryEggs(2);
Console.WriteLine("eggs are ready");
Bacon bacon = await FryBacon(3);
Console.WriteLine("bacon is ready");
Toast toast = await ToastBread(2);
ApplyButter(toast);
ApplyJam(toast);
Console.WriteLine("toast is ready");
Juice oj = PourOJ();
Console.WriteLine("oj is ready");

Console.WriteLine("Breakfast is ready!");
}
// </SnippetMain>

private static Juice PourOJ()
{
Console.WriteLine("Pouring Orange Juice");
return new Juice();
}

private static void ApplyJam(Toast toast) => Console.WriteLine("Putting jam on the toast");

private static void ApplyButter(Toast toast) => Console.WriteLine("Putting butter on the toast");

private static async Task<Toast> ToastBread(int slices)
{
for (int slice = 0; slice < slices; slice++)
Console.WriteLine("Putting a slice of bread in the toaster");
Console.WriteLine("Start toasting...");
await Task.Delay(3000);
Console.WriteLine("Remove toast from toaster");
return new Toast();
}

private static async Task<Bacon> FryBacon(int slices)
{
Console.WriteLine($"putting {slices} of bacon in the pan");
Console.WriteLine("cooking first side of bacon...");
await Task.Delay(3000);
for (int slice = 0; slice < slices; slice++)
Console.WriteLine("flipping a slice of bacon");
Console.WriteLine("cooking the second side of bacon...");
await Task.Delay(3000);
Console.WriteLine("Put bacon on plate");
return new Bacon();
}

private static async Task<Egg> FryEggs(int howMany)
{
Console.WriteLine("Warming the egg pan...");
await Task.Delay(3000);
Console.WriteLine($"cracking {howMany} eggs");
Console.WriteLine("cooking the eggs ...");
await Task.Delay(3000);
Console.WriteLine("Put eggs on plate");
return new Egg();
}

private static Coffee PourCoffee()
{
Console.WriteLine("Pouring coffee");
return new Coffee();
}
}
}
8 changes: 8 additions & 0 deletions snippets/csharp/tour-of-async/AsyncBreakfast-V2/Toast.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
using System;

namespace AsyncBreakfast
{
internal class Toast
{
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp2.2</TargetFramework>
<LangVersion>latest</LangVersion>
</PropertyGroup>

</Project>
6 changes: 6 additions & 0 deletions snippets/csharp/tour-of-async/AsyncBreakfast-V3/Bacon.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
namespace AsyncBreakfast
{
internal class Bacon
{
}
}
6 changes: 6 additions & 0 deletions snippets/csharp/tour-of-async/AsyncBreakfast-V3/Coffee.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
namespace AsyncBreakfast
{
internal class Coffee
{
}
}
6 changes: 6 additions & 0 deletions snippets/csharp/tour-of-async/AsyncBreakfast-V3/Egg.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
namespace AsyncBreakfast
{
internal class Egg
{
}
}
6 changes: 6 additions & 0 deletions snippets/csharp/tour-of-async/AsyncBreakfast-V3/Juice.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
namespace AsyncBreakfast
{
internal class Juice
{
}
}
Loading