-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for multiple interfaces and more samples.
- Loading branch information
Showing
6 changed files
with
85 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
namespace Dunet.Choices; | ||
|
||
[Union] | ||
internal interface IChoice | ||
{ | ||
void Yes(); | ||
void No(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,44 @@ | ||
// See https://aka.ms/new-console-template for more information | ||
|
||
using Dunet.Choices; | ||
using Dunet.Shapes; | ||
|
||
var rectangle = new Rectangle(10, 10); | ||
var triangle = new Triangle(10, 10); | ||
var circle = new Circle(10); | ||
|
||
var rectangleArea = Calculator.GetArea(rectangle); | ||
var triangleArea = Calculator.GetArea(triangle); | ||
var circleArea = Calculator.GetArea(circle); | ||
var getArea = (IShape shape) => | ||
shape switch | ||
{ | ||
Rectangle rect => rect.Length * rect.Width, | ||
Circle circle => 2.0 * Math.PI * circle.Radius, | ||
Triangle triangle => 1.0 / 2.0 * triangle.Base * triangle.Height, | ||
_ => 0d, | ||
}; | ||
|
||
var rectangleArea = getArea(rectangle); | ||
var triangleArea = getArea(triangle); | ||
var circleArea = getArea(circle); | ||
|
||
Console.WriteLine($"Rectangle area: {rectangleArea}"); | ||
Console.WriteLine($"Triangle area: {triangleArea}"); | ||
Console.WriteLine($"Circle area: {circleArea}"); | ||
|
||
class Calculator | ||
var choice = GetChoice(); | ||
|
||
if (choice is Yes) | ||
{ | ||
Console.WriteLine("YES!!!"); | ||
} | ||
|
||
if (choice is No) | ||
{ | ||
public static double GetArea(IShape shape) => | ||
shape switch | ||
{ | ||
Rectangle rect => rect.Length * rect.Width, | ||
Circle circle => 2.0 * Math.PI * circle.Radius, | ||
Triangle triangle => 1.0 / 2.0 * triangle.Base * triangle.Height, | ||
_ => 0d, | ||
}; | ||
Console.WriteLine("NO!!!"); | ||
} | ||
|
||
static IChoice GetChoice() => | ||
Console.ReadLine() switch | ||
{ | ||
"yes" => new Yes(), | ||
_ => new No(), | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters