public class a
{
public void PrintArray(int[,] d,int row,int col)
{
for(int i=0;i<row;i++)
{
for(int j=0;j<col;j++)
{
Console.WriteLine(d[i,j]+"\t");
}
}
}
public int martixmul(int[,] x,int[,] y)
{
int[,] c= new int[2,2];
int n=0;
for(int i=0;i<2;i++)
{
for(int j=0;j<2;j++)
{
n=0;
for( int k=0;k<3;k++)
n=n+x[i,k]*y[k,j];
c[i,j]=n;
}
PrintArray(c,2,2);
}
}
public static void Main()
{
a mya=new a();
int[,] a=new int[2,3];
int[,] b=new int[3,2];
for(int i=0;i<2;i++)
{
for(int j=0;j<3;j++)
{
a[i,j]=i+j;
} }
Console.WriteLine(" output array a:");
mya.PrintArray(a,2,3);
for(int i=0;i<3;i++)
{
for(int j=0;j<2;j++)
{
b[i,j]=i+j;
} }
Console.WriteLine(" output array b:");
mya.PrintArray(b,3,2);
Console.WriteLine("a and b of result:");
mya.martixmul(a,b);
Console.ReadLine();
}
}
}
c:\inetpub\wwwroot\c\a.cs(21): “c.a.martixmul(int[*,*], int[*,*])” : 并非所有的代码路径都返回值
{
public void PrintArray(int[,] d,int row,int col)
{
for(int i=0;i<row;i++)
{
for(int j=0;j<col;j++)
{
Console.WriteLine(d[i,j]+"\t");
}
}
}
public int martixmul(int[,] x,int[,] y)
{
int[,] c= new int[2,2];
int n=0;
for(int i=0;i<2;i++)
{
for(int j=0;j<2;j++)
{
n=0;
for( int k=0;k<3;k++)
n=n+x[i,k]*y[k,j];
c[i,j]=n;
}
PrintArray(c,2,2);
}
}
public static void Main()
{
a mya=new a();
int[,] a=new int[2,3];
int[,] b=new int[3,2];
for(int i=0;i<2;i++)
{
for(int j=0;j<3;j++)
{
a[i,j]=i+j;
} }
Console.WriteLine(" output array a:");
mya.PrintArray(a,2,3);
for(int i=0;i<3;i++)
{
for(int j=0;j<2;j++)
{
b[i,j]=i+j;
} }
Console.WriteLine(" output array b:");
mya.PrintArray(b,3,2);
Console.WriteLine("a and b of result:");
mya.martixmul(a,b);
Console.ReadLine();
}
}
}
c:\inetpub\wwwroot\c\a.cs(21): “c.a.martixmul(int[*,*], int[*,*])” : 并非所有的代码路径都返回值
这个方法没有返回。
要么 return n;
要么public void martixmul(int[,] x,int[,] y)
就是所 你的程序中的方法:c.a.martixmul(int[*,*], int[*,*])
并没有返回任何的与它声明的返回值类型匹配的返回值!
所以楼主先看看你的return 语句在此函数中的位置是不是正确的 。
using System;
public class a
{
public void PrintArray(int[,] d,int row,int col)
{
for(int i=0;i<row;i++)
{
for(int j=0;j<col;j++)
{
Console.WriteLine(d[i,j]+"\t");
}
}
}
public int martixmul(int[,] x,int[,] y)
{
int[,] c= new int[2,2];
int n=0;
for(int i=0;i<2;i++)
{
for(int j=0;j<2;j++)
{
n=0;
for( int k=0;k<3;k++)
n=n+x[i,k]*y[k,j];
c[i,j]=n;
}
PrintArray(c,2,2);
}
return n;//加此代码
} public static void Main()
{
a mya=new a();
int[,] a=new int[2,3];
int[,] b=new int[3,2];
for(int i=0;i<2;i++)
{
for(int j=0;j<3;j++)
{
a[i,j]=i+j;
}
}
Console.WriteLine(" output array a:");
mya.PrintArray(a,2,3);
for(int i=0;i<3;i++)
{
for(int j=0;j<2;j++)
{
b[i,j]=i+j;
} }
Console.WriteLine(" output array b:");
mya.PrintArray(b,3,2);
Console.WriteLine("a and b of result:");
mya.martixmul(a,b);
Console.ReadLine();
}}