我對C#真的很陌生。我有多個計算機實例,每個計算機實例都有一個名稱,停止,啓動和重新啓動與每個計算機相關的命令。我想從文件中讀取信息。具有多個對象的陣列陣列
所以我想最終以instancelist[0].Instance_name=Enterprise1
和instancelist[0][email protected]_stop
和instancelist[1].Instance_name=Enterprise5
等等。我可以弄清楚如何做這個聲明。
public class Instance
{
public string Instance_name;
public string Instance_stop;
public string Instance_restart;
public string Instance_backup;
}
public static void Main(string[] args)
{
int num_instances=0;
/** CAN'T figure out the declaration. I'm currently thinking array of array? */
System.IO.StreamReader file = new System.IO.StreamReader(@"C......");
while(true)
{
instancelist[num_instance].Instance_name=file.ReadLine();
instancelist[num_instance].Instance_stop=file.ReadLine();
// and so on.......
num_instance++;
}
}
我猜你是在談論「鋸齒狀」陣列:這裏是解釋用法的鏈接:http://msdn.microsoft.com/en-us/library/2s05feca.aspx – 2013-05-09 00:21:29
您好!我花時間格式化代碼,但將來你應該在發佈你的問題之前讓你的代碼呈現出來。 (要立即發佈大量代碼,請使用「代碼示例」選擇將其全部縮進四個空格,這會使其格式化爲代碼) – Patashu 2013-05-09 00:22:05