TemparatureConverter/Program.cs

74 lines
1.8 KiB
C#

TemparatureConverter converter = new TemparatureConverter();
ITemperatureUnit fromUnit = null;
float value = 0f;
string input = "";
do
{
Console.WriteLine("Which type do you want to convert from?");
foreach (var unitPair in converter.Dictionary)
Console.WriteLine(unitPair.Key);
Console.Write("Unit: ");
input = Console.ReadLine();
converter.Dictionary.TryGetValue(input, out fromUnit);
} while (fromUnit == null);
Console.WriteLine("");
do
{
Console.WriteLine("The value you want to convert?");
Console.Write("Value: ");
} while (!float.TryParse(Console.ReadLine(), out value));
Console.WriteLine("");
fromUnit = converter.Dictionary["Celcius"];
value = 100;
foreach (var toUnitPair in converter.Dictionary)
{
float convertedValue = converter.Convert(value, fromUnit, toUnitPair.Value);
Console.WriteLine($"{toUnitPair.Key} -> {convertedValue}");
}
// do
// {
// Console.WriteLine("Which type do you want to convert to?");
// foreach (var unitPair in converter.Dictionary)
// Console.WriteLine(unitPair.Key);
// } while (!converter.Dictionary.TryGetValue(Console.ReadLine(), out toUnit));
// Action<char> OnKeyPressed = null;
// Action OnBooleanBecameTrue = null;
// bool _booleanToBeTracked = false;
// bool BooleanToBeTracked
// {
// get => _booleanToBeTracked;
// set
// {
// _booleanToBeTracked = value;
// if (value)
// OnBooleanBecameTrue?.Invoke();
// }
// }
// OnKeyPressed += SayHi;
// OnKeyPressed += SayHiAnother;
// void SayHi(char key)
// => Console.WriteLine($"\n{key} was pressed!");
// void SayHiAnother(char key)
// => Console.WriteLine($"\n{key} WaSSSSSS pressed!");
// while (true)
// OnKeyPressed?.Invoke(Console.ReadKey().KeyChar);