using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;namespace ConsoleApplication4
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("请输入第一个数字");
            Console.WriteLine("请输入运算符 '+' '-' '*' '/'");
            Console.WriteLine("请输入第二个数字");
            Console.WriteLine(Jsq.str());
            Console.Read();
        }
    }
   class Jsq
    {
        public static string str()
        {
            int a = int.Parse(Console.ReadLine());
            int b = int.Parse(Console.ReadLine());
            string c = Console.ReadLine();            if (c == "+")
            {
                int result;
                result = a + b;
                Console.WriteLine("结果是{0}", result);
            }
            else if (c == "-")
            {
                int result;
                result = a - b;
                Console.WriteLine("结果是{0}", result);
            }
            else if (c == "*")
            {
                int result;
                result = a * b;
                Console.WriteLine("结果是{0}", result);
            }
            else if (c == "/")
            {
                int result;
                result = a / b;
                Console.WriteLine("结果是{0}", result);
            }
            else
            {
                Console.WriteLine("请输入有效的运算符");
            }         }
    }
}

解决方案 »

  1.   

    错误提示已经很明显了,你的str方法返回的是一个string,但你的if判断里最后那个else如果条件为真,你返回什么string呢?
      

  2.   

    那我把str方法 可以改掉吗 应该怎么改啊 或者把最后一个else删了 
      

  3.   

    全篇没一个return,你到底要不要返回?
      

  4.   

    看错了,同楼上,你的str在哪里返回这个string呢
      

  5.   

       public static string str()  这个方法要求返回string类型,你没有返回值,加个return result ; 或者直接改为  public static void str()  .
      

  6.   


    //很明显,你的str函数木有return啊
    public static string str()
    {}