我想将此方法中的foreach转换为linq表达式.我有2次尝试/捕获因为我不能总是指望在guid或guidToFind列表中传递的字符串是有效的guid字符串.
public static bool IsGuidInList(List<string> guids, string guidToFind)
{
try
{
var guid = new Guid(guidToFind.Trim());
foreach (var g in guids)
{
try
{
var g2 = new Guid(g.Trim());
if (g2 == guid)
return true;
}
catch {} // swallow exception
}
}
catch{} // swallow exception
return false;
}
Run Code Online (Sandbox Code Playgroud)