有人可以向我解释我的代码有什么问题吗?

Can someone explain to me what's wrong with my code please?

我一直在学习 C#,现在我正在尝试创建一个计算器来读取您的输入以学习如何正确读取输入。如果它真的很简单,我很抱歉我是新手。 该错误表明它无法将 (10,20) 和 (14,20) 上的 int 转换为字符串。

using System;

class Calculator {
static void Main() {
    int n1, n2;
    string operation;


    Console.Write("First number: ");
        n1 = int.Parse(Console.Read());
    Console.Write("Operation: ");
        operation = Console.ReadLine();
    Console.Write("Second number: ");
        n2 = int.Parse(Console.Read());

        if (operation == "+") {
            Console.Write(n1 + n2);
        }else if (operation == "-") {
            Console.Write(n1 - n2);
        }else if (operation == "*") {
            Console.Write(n1 * n2);
        }else if (operation == "/") {
            Console.Write(n1 / n2);
        };

    }
} ```

拨打所有电话 Console.ReadLine() 而不是 Console.Read()

确保为操作数键入一个整数。如果您输入的不是整数(我无法确定您的 10,20 是否表示您的操作数是 10 和 20,或者您来自使用逗号作为小数分隔符且 10,20 是 10 的国家/地区and-a-fifth) 那么你将无法使用 int.Parse 解析十进制数,请尝试 decimal.Parse 并更改所有数据类型

使用 Console.Read() 将读取单个字符和 return 它的数值,例如 1 个字符的 int 值为 31(看看 ascii table) 这将非常令人困惑,更令人困惑的是如何将 A(ascii 值 65)添加到 B(66 - 结果 131):) ...

试试点。 10.20 和 14.20。 也试试 ReadLine

试试这个作为 10 岁的入门者。我相信有很多方法可以更有效地做到这一点,但这应该会给你一些想法:

using System;

namespace Calculator
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.Write("First Number: ");
            int a = int.Parse(Console.ReadLine());

            Console.Write("Operation: ");
            string operation = Console.ReadLine();

            Console.Write("Second number: ");
            int b = int.Parse(Console.ReadLine());

            switch(operation)
            {
                case "+":
                    Console.WriteLine(string.Format("Result: {0}", (a + b)));
                    break;

                case "-":
                    Console.WriteLine(string.Format("Result: {0}", (a - b)));
                    break;

                case "*":
                    Console.WriteLine(string.Format("Result: {0}", (a * b)));
                    break;

                case "/":
                    Console.WriteLine(string.Format("Result: {0}", (a / b)));
                    break;
            }
            Console.WriteLine("Press any key to close...");
            Console.ReadKey();
        }
    }
}