Cannot convert from method group to Int32

后端 未结 3 1824
孤城傲影
孤城傲影 2021-01-22 00:25

I want my small math program to look really sleek, and by this I mean under the Main method I have the following methods:

Greet()
UserInput1()
UserI         


        
3条回答
  •  后悔当初
    2021-01-22 01:25

    Cannot convert from method group to int

    This error message occurs when you attempt to take a method (without invocation) and pass it as a type. The result method is expecting two parameters of type int, but you're attempting to pass it the method, rather than the result of the method invocation.

    You need to store the results in a variable, or invoke the methods with the ():

    Like this:

    static void Main(string[] args)
    {
        Greet();
        var first = firstNumber();
        var second = secondNumber();
        result(first , second );
        Console.ReadKey(); 
    }
    

    or this:

    static void Main(string[] args)
    {
        Greet();
        result(firstNumber(), secondNumber());
        Console.ReadKey(); 
    }
    

提交回复
热议问题