我是一个新手,我试图在Main中的构造函数中创建Console.Write()数组。我也尝试将ToString()重写为Console.Write()作为一个字符串数组,但没有找到一个线索如何做到这一点。使用数组构造函数创建对象
namespace Z1
{
class List
{
public List(int b)
{
int[] tabb = new int[b];
Random r1 = new Random();
for(int i=0;i<b;i++)
{
tabb [i] =r1.Next(0, 100);
}
}
public List()
{
Random r2 = new Random();
int rInt1=r2.Next(0,10);
int[] tabc = new int[rInt1];
Random r3 = new Random();
for(int i=0;i<rInt1;i++){
tabc [i] = r3.Next(0,100);
}
}
}
class Program
{
static void Main()
{
List l1 = new List(10);
List l2 = new List();
Console.WriteLine(l1.ToString());
Console.WriteLine(l2.ToString());
}
}
}
你有没有尝试过使用谷歌搜索“如何在C#中覆盖ToString”? – Abion47