这个C#代码有什么问题?我试图重载+运算符以添加两个数组,但收到如下错误消息:
二元运算符的参数之一必须是包含类型.
class Program
{
public static void Main(string[] args)
{
const int n = 5;
int[] a = new int[n] { 1, 2, 3, 4, 5 };
int[] b = new int[n] { 5, 4, 3, 2, 1 };
int[] c = new int[n];
// c = Add(a, b);
c = a + b;
for (int i = 0; i < c.Length; i++)
{
Console.Write("{0} ", c[i]);
}
Console.WriteLine();
}
public static int[] operator+(int[] x, int[] y)
// public …Run Code Online (Sandbox Code Playgroud)