Пример #1
0
        static void Main(string[] args)
        {
            float ftemp             = 32F;
            float ctemp             = 0F;
            FahrenheitTemperature c = new FahrenheitTemperature(ftemp);
            var cresult             = (CelsiusTemperature)c;

            Console.WriteLine(cresult.temp);

            Console.WriteLine("****************");

            CelsiusTemperature f = new CelsiusTemperature(ctemp);
            var fresult          = (FahrenheitTemperature)f;

            Console.WriteLine(fresult.temp);
            Console.ReadLine();
        }
Пример #2
0
        static void Start()
        {
            Console.Write("Input a temperature followed by an F for Fahrenheit or a C for Celsius: ");
            string input = Console.ReadLine().ToUpper();
            FahrenheitTemperature fTemp;
            CelsiusTemperature    cTemp;

            switch (input[input.Length - 1])
            {
            case 'F':
                input = input.TrimEnd('F');
                if (Double.TryParse(input, out double fTempValue))
                {
                    fTemp = new FahrenheitTemperature(fTempValue);
                    cTemp = (CelsiusTemperature)fTemp;
                    Output(fTemp, cTemp);
                }
                else
                {
                    invalidInput();
                }
                break;

            case 'C':
                input = input.TrimEnd('C');
                if (Double.TryParse(input, out double cTempValue))
                {
                    cTemp = new CelsiusTemperature(cTempValue);
                    fTemp = (FahrenheitTemperature)cTemp;
                    Output(fTemp, cTemp);
                }
                else
                {
                    invalidInput();
                }
                break;

            default:
                invalidInput();
                break;
            }
        }