并非所有代码路径都返回值

  public static int Get(string a)
        {
            bool b = true;
            while (b)
            {
               
                try
                {
                    int c = Convert.ToInt32(a);
                    b = false;
                    return c;
                }
                catch
                {
                    Console.WriteLine("你输入的不对,请重新输入");
                    a = Console.ReadLine();
                    return 0;
                }
            }
            
        }

一直提示get函数 并非所有代码路径都返回值,我该怎样修改?

while 外面需要有个返回值,如果不进while 这个函数就没有返回值了

试试把第10行删掉,就是b = false;那行

 

 public static int Get(string a)
        {
            bool b = true;
            do
            {
                try
                {
                    int c = Convert.ToInt32(a);
                    b = false;
                    return c;
                }
                catch
                {
                    Console.WriteLine("你输入的不对,请重新输入");
                    a = Console.ReadLine();
                    return 0;
                }
            } while (b);
        }

 

谢谢各位,已经折腾明白了