class Program
{
struct St_test
{
public string f_name;
public string l_name;
public int age;
public string email;
}
static void proced(int number)
{
St_test s = new St_test();
Console.WriteLine("Enter the first name :");
s.f_name = Console.ReadLine();
Console.WriteLine("Enter the last name :");
s.l_name = Console.ReadLine();
agee:
Console.WriteLine("Enter the age :");
try { s.age = int.Parse(Console.ReadLine()); }
catch { Console.WriteLine("You enterd viod age"); goto agee; }
Console.WriteLine("Enter the e_mail :");
s.email = Console.ReadLine();
}
static void Main(string[] args)
{
int num;
nume:
Console.WriteLine("enter the count of people you would like to store");
try { num = int.Parse(Console.ReadLine()); }
catch { Console.WriteLine("you enterd void number"); goto nume; }
for (int i = 0; i < num; i++)
{
proced(num);
}
我想輸入許多(S)到每個數字(num)的人。C#將變量的值轉換爲變量
如何重複該程序(程序)並且每次重複(s)變量都有新名稱。
如果我在過程(proced)接下來寫:
string r = "s" + number;
如何將導致串(R),以變量轉換爲用它代替(S)變量每個循環
你試過使用循環,像一個while循環? – Yordan
是的我用(for循環)方法把它同樣的問題 –
這聽起來像你需要了解集合和數組。 (我也強烈建議不要創建像這樣的可變值類型 - 和公共字段。瞭解屬性和.NET命名約定。) –