如果 country 不等 CN 也不等于 TW, 那不是函数就没有返回值了?所以在最后面还要返回一个值,来表示不等于 CN, TW, 如:if(country=="CN")
{
return 1;
}
else if (country=="TW")
{
return 2;
}
else
{
  return 3;
}

解决方案 »

  1.   

    这样是错的,你要:
    if(country=="CN")
    {
    return 1;
    }
    else
    {
    return 2;
    }
      

  2.   

    因为电脑不知道你只有CN和TW2个值啊!
      

  3.   


    if(country=="CN")
    {
    return "1";
    }
    else if (country=="TW")
    {
    return "2";
    }
                                //这里必须有返回值。
      

  4.   


    以上正确,额外说一句,如果使用以下写法,程序性能会好写:if(country.Equals("CN"))
    {
       return 1;
    }
    else
    {
       return 2;
    }能用Equals就用而少用"=="
      

  5.   

    如果只有"CN"和"TW"两个值的话,这样写性能最好:
    if (country.Equals("CN"))
    {
       return 1;
    }
    return 2;
      

  6.   

    假设country只为cn或tw两种情况
    if(country=="CN")
    {
    return 1;
    }
    return 2;
      

  7.   

    我看还是用switch吧
    这样好像要好一点吧
      

  8.   

    我觉得你先检查一下你的函数是不是没有返回值void的,函数要有返回值才可以的,
      

  9.   

    你要看看你这个函数是返回什么类型,如果是STRING 肯定不行。