我有一個由名字組成的數組_姓,這樣他們就看,像這樣 Michael_Jordan Javier_Lopez George_Jones如何拆分即宣告全球
陣列我有一個循環建立通過每個迭代這些,但我只想採取「」後面的問題我所擁有的問題是,該數組是全局聲明的,並且它在很多地方被聲明爲我改變的地方。如果我嘗試使用.Split函數,則會收到System.Array的錯誤,其中不包含用於分割的定義。在陣列中的「」之後採用數據的另一種選擇是什麼?
public static string GetEmployees()
{
string queryString = "select employeeName from tbl_GlobalEmployeeData where state = 'AL';
SqlConnection connection = new SqlConnection(Connection.MyConnectionString.ConnectionStrings[0]);
{
SqlCommand cmd = new SqlCommand(queryString, connection);
connection.Open();
List<string> tempList = new List<string>();
SqlDataReader reader = cmd.ExecuteReader();
while (reader.Read())
{
try
{
if (!reader.IsDBNull(0))
{
tempList.Add(reader[0].ToString() + "_" + reader[1].ToString());
}
}
catch
{
if (!reader.IsDBNull(0))
{
tempList.Add(reader[0].ToString() + "_" + reader[1].ToString());
}
}
}
reader.Close();
AllCompanyEmployees.State.ThisStore = tempList.ToArray();
for (int q = AllCompanyEmployees.State.ThisStore.GetLowerBound(0); q <= AllCompanyEmployees.State.ThisStore.GetUpperBound(0); q++)
{
return AllCompanyEmployees.State.ThisStore[q];
}
return null;
}
}
}
for (int q = AllCompanyEmployees.State.ThisStore.GetLowerBound(0); q <= AllCompanyEmployees.State.ThisStore.GetUpperBound(0); q++)
{
//This line is where I get the error mentioned above
string lastName = AllCompanyEmployees.State.ThisStore.Split('_')[1];
}
我看不到您的問題和代碼之間的連接。你粘貼了錯誤的代碼片段嗎? – Baldrick
''「'之後?什麼都沒有?你在說什麼?你的意思是分割下劃線嗎?請爲您的全局數組顯示代碼,並澄清您正在嘗試使用哪些示例。另外,你不能在數組上使用'Split'。這是'String'的一種方法。你需要在數組中的單個字符串上使用'Split'。 – tnw
道歉到2試圖幫助,我沒有發佈錯誤的代碼片段。請查看我編輯中發佈的代碼。 – user2932408