c# 数组对象不能作为返回对象,但是List对象却可以作为返回对象?

来源:百度知道 编辑:UC知道 时间:2024/05/22 19:52:47

public int[] a;
.....
程序中直接使用a
或者
private int[] a;
......
public int[] getA()
{
return a;
}
程序中直接调用getA()方法

学习下

请高手

数组和List都可以作为返回对象。把出问题的代码贴上来看看哪里出的问题。

任何符合C#规范的对象都可以作为返回值

using System;
using System.Collections.Generic;
using System.Text;

namespace baidu._0081105
{
class Program
{
static void Main(string[] args)
{
char[] a ={ '0', '1', '2','3' };
new arr(a).ToString ();
Console.WriteLine(new arr(a).toint ());
}
}
class arr
{
char [] a;
public arr(char[] a)
{
this.a = a;
}
public new void ToString()
{
string s = string.Empty;
for (int i = 0; i < a.Length; i++)