المساعد الشخصي الرقمي

مشاهدة النسخة كاملة : Using an Array inside a Class



C# Programming
08-30-2012, 02:11 AM
I'm fairly new to programming in general and C# in particular. Following code throws an "Object reference not set to an instance of an object" exception.

public class quote { ... public string[] data; public string[] date; public string[] release; public string[] baseID; ... DataTable t2 = new DataTable(); //fill the datatable ... //code that doesn't work for (int i = 0; i < t2.rows.count + 1; i++) { DataRow r2 = t2.Rows[i]; this.baseID[i] = (string)r2["BASE_ID"]; this.data[i] = (string)r2["Data"]; this.date[i] = Convert.ToString(r2["Date"]); this.release[i] = (string)r2["Release"]; }
I think I understand why it doesn't work....but I'm not sure what I should be doing instead. Any help is greatly appreciated.