int search(string [][]mat, int n, string x){
//set indexes for top right element
for(int i = 0; i<n; i++)
{
for(int j = n-1; j>=0; j--)
{
if ( mat[i][j] == x )
{
Debug.Log(x +""+"Found at "+i +" "+j);
// int[] n2 = new int[] {2, 4, 6, 8};
// int [] xyz = new int [] {i, j};
return i;
}
}
}}
如何解决这个错误:not all code paths return a value?
错误信息: *Assets/Scripts/Chess/Bishop.cs(237,22): error CS0161: `Bishop.search(string[][], int, string)': not all code paths return a value*
问题原因是该函数的所有代码路径都没有返回值。需要在函数中添加返回语句,确保所有情况下都有返回值。