我做了一個靜態函數返回我對象的ArrayList:問題有關與的ArrayList在C#中處理
allThread =(ArrayList) AllQuestionsPresented.GetAllThreads();
現在有對象,我想出去性質。但我注意到我不能輸入allThreads.Name ...或者allThreads [「Name」]或allThreads [1],它不會給我這個對象本身。原因智能感知犯規承認它..
這裏就是我想要做..:
這個函數是一個類:
public static ICollection GetAllThreads()
{
ArrayList allThreads = new ArrayList();
string findUserID = "SELECT UserID FROM Users";
string myConnectionString = AllQuestionsPresented.connectionString;
using (SqlConnection myConnection = new SqlConnection(myConnectionString))
{
SqlCommand sqlCommand = new SqlCommand(findUserID, myConnection);
SqlDataReader reader = sqlCommand.ExecuteReader();
while (reader.Read())
{
AllQuestionsPresented allQ = new AllQuestionsPresented((Guid)reader["UserID"]);
allThreads.Add(allQ);
}
}
return allThreads;
}
從另一個函數的一些代碼另一個類:
forumsPages = new Dictionary<int, List<DisplayAllQuestionsTable>>();
allThread =(ArrayList) AllQuestionsPresented.GetAllThreads();//I want to convert the ICollection
for (int i = 0; i < 20; i++)
{
threads.Add(new DisplayAllQuestionsTable(allThread[i].//And use it here. I want an object to be returned..same object that was stored in the ArrayList in the static function
}
感謝您的代碼 – Matrix001 2011-06-07 18:14:45