我认为我的代码应该使
为什么会这样?
ViewBag.test
属性等于"No Match"
,但实际上它抛出了一个InvalidOperationException
异常。
为什么会这样?
为什么会这样?
string str = "Hello1,Hello,Hello2";
string another = "Hello5";
string retVal = str.Split(",".ToCharArray(), StringSplitOptions.RemoveEmptyEntries)
.First(p => p.Equals(another));
if (str == another)
{
ViewBag.test = "Match";
}
else
{
ViewBag.test = "No Match"; //this does not happen when it should
}
InvalidOperationException
,而是抛出它。主要是因为该列表中没有任何一个字符串等于“Hello5”。你想要实现什么? - It'sNotALie.