禁止转换-.NET
当我编10进制转换成16进制的时候,为什么有“错误 1 “ShiToOthers.ShiToOthers.ShiToShiLiu(string)”: 并非所有的代码路径都返回值 ”这样的报错呢?我是新手,所以有很多不懂,忘相助。
public string ShiToShiLiu(string i)
{
Int64 x = Convert.ToInt64(i);
Int64 count = 0;
while (x != 0)
{
Int64 yu;
char c;
char[] a = new char[100];
string str = "";
while (x != 0)
{
yu = x % 16;
switch (yu)
{
case 10: c = 'A'; break;
case 11: c = 'B'; break;
case 12: c = 'C'; break;
case 13: c = 'D'; break;
case 14: c = 'E'; break;
case 15: c = 'F'; break;
default: c = (char)(yu + 48); break;
}
a[count] = c;
count++;
x = x / 16;
}
for (Int64 j = count - 1; j >= 0; j++)
{
str = str + a[j].ToString();
}
return str;
}
主函数是这样的:
static void Main(string[] args)
{
ShiToOthers ZH = new ShiToOthers();
string str = Console.ReadLine();
string str1 = ZH.ShiToShiLiu(str);
Console.WriteLine(str1);
Console.ReadKey();
}
------解决方案--------------------
return str; 写在while里面了