0
當我運行它跳過第一個readline並重復第一個「for」無限次
起初,它給了我nullreferenceexception錯誤,這就是當我添加第一行首先爲
我是新來的編碼所以請讓該解決方案是簡單跳過readline並重復無限次與數組c#
這是代碼:使用Console.Read()
和Console.ReadLine()
當
class People
{
public string name;
public string address;
public int age;
public void setvalues(string na, string ad, int ag)
{
this.name = na;
this.address = ad;
this.age = ag;
}
}
class Program
{
static void Main(string[] args)
{
Console.Write("Enter the number of People you want to add : ");
int q = Convert.ToInt32(Console.Read());
People[] plist = new People[q];
string[] namelist = new string[q];
string[] addresslist = new string[q];
int[] agelist = new int[q];
for (int i = 0; i < q; i++)
{
plist[i] = new People();
Console.WriteLine("Enter the name of the person : ");
namelist[i] = Console.ReadLine();
Console.Write("Enter the address of the person : ");
addresslist [i] = Console.ReadLine();
Console.Write("Enter the age of the person : ");
agelist[i] =Convert.ToInt32(Console.ReadLine());
}
for (int s = 0; s < q; s++)
{
plist[s].setvalues (namelist[s], addresslist[s], agelist[s]);
}
}
}
}
感謝您的有用和真正的快速答覆。 –