我有一个List <>,其中包含另一个List <>
我需要查找最内层列表中的任何项目中是否存在给定值.如果找到匹配,我需要该特定项目并返回.
我这样做如下所示:
InnerList inner = null;
foreach(TopList in topListItems)
{
inner = asn.Owners.Find(x => x.GuestId == guestId);
if(inner != null)
break;
}
//item found if inner is not null
//else item absent in the inner list
Any other alternate way that may run faster than this?
Run Code Online (Sandbox Code Playgroud)
编辑: 一些更正:我只需要看看内部列表是否有一个具有特定值的项目.如果是,那么我需要返回具有匹配项的顶级项目.我猜逻辑是一样的.
我有一个代码块来处理我的应用程序中的异常,它使用if/else块来获取消息内容.
我的代码如下:
// define variable to hold exceptions...
var exceptionMessage = new StringBuilder();
// based on the exception type...
if (expType == typeof(EntityValidationException))
{
// append the relevant message to the text...
exceptionMessage.Append(exception.InnerException.Message);
}
else if (expType == typeof(ValidationException))
{
// This is the type of error generated when entities are validated
var validationException = (ValidationException)exception;
exceptionMessage.Append(validationException.InnerException.Message);
}
else if (expType == typeof(DomainSecurityException))
{
// These are security breaches
var domainSecurityException = (DomainSecurityException)exception;
exceptionMessage.Append(domainSecurityException.InnerException.Message);
}
else if (expType == typeof(DomainInternalMessageException)) …Run Code Online (Sandbox Code Playgroud)