在windows窗體應用程序中,類的List<>
將按方法檢查,其返回類型爲bool。捕捉未處理的異常和停止方法?
示例如果有100個類,只有1個類返回false
那麼它是另一個字段(Reqbool
)將是fals
e。當所有課程獲得true
回報時,只有Reqbool
將爲true
。
有沒有簡單的方法可以解決這個問題?它說異常是未處理的,並且每個false
返回它顯示的消息框。
bool Reqbool = true;
bool MiniReqbool;
if(MiniReqbool == false) { throw new Exception(); }
try
{
for (int i = 0; i < ImportList.Count; i++)
{
MiniMiniTest mitest = new MiniMiniTest();
MiniReqbool = mitest.ReqTest(ImportList[i], QValue);
}
}
catch (Exception)
{
Reqbool = false;
MessageBox.Show("Sorry points not found");
}
你的問題真的不清楚,那可能是語言障礙。我想你正在尋找'Enumerable.All()'或'Enumerable.Any()',但我不能告訴。 – Jamiec
因此,如果'mitest.ReqTest'返回''false'爲'ImportList'中的任何項目,您希望'Reqbool'爲'false'? – TheLethalCoder
@ TheLethalCoder絕對是! – ldn