本文整理汇总了C#中System.Collections.Generic.System.Collections.Generic.List.FirstOrDefault方法的典型用法代码示例。如果您正苦于以下问题:C# System.Collections.Generic.List.FirstOrDefault方法的具体用法?C# System.Collections.Generic.List.FirstOrDefault怎么用?C# System.Collections.Generic.List.FirstOrDefault使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Collections.Generic.System.Collections.Generic.List
的用法示例。
在下文中一共展示了System.Collections.Generic.List.FirstOrDefault方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CacheTables
/// <summary>
/// Constructor
/// </summary>
/// <param name="Reader">Reader to copy from</param>
public CacheTables(IDataReader Reader)
{
CacheTables Temp = Reader as CacheTables;
if (Temp!=null)
{
this.Tables = Temp.Tables;
CurrentTable = Tables.FirstOrDefault();
CurrentRow = CurrentTable[0];
CurrentTablePosition = 0;
RowPosition = -1;
return;
}
Tables = new System.Collections.Generic.List<Table>();
Tables.Add(new Table(Reader));
while (Reader.NextResult())
{
Tables.Add(new Table(Reader));
}
CurrentTable = Tables.FirstOrDefault();
CurrentRow = CurrentTable[0];
CurrentTablePosition = 0;
RowPosition = -1;
}
示例2: LoadAssociatedItemsForAccount
public System.Collections.Generic.List<GroupByCreateTimeAccountItemViewModel> LoadAssociatedItemsForAccount(Account itemCompareToCurrent, ObservableCollection<GroupByCreateTimeAccountItemViewModel> out_container)
{
this.HasLoadAssociatedItemsForCurrentViewAccount = true;
System.Collections.Generic.List<GroupByCreateTimeAccountItemViewModel> container = new System.Collections.Generic.List<GroupByCreateTimeAccountItemViewModel>();
int recordCount = 0;
int num = 0;
System.Action<Int32, String> action = delegate(int count, string name)
{
recordCount += count;
Deployment.Current.Dispatcher.BeginInvoke(delegate
{
GlobalIndicator.Instance.BusyForWork(AppResources.NowLoadingFormatter.FormatWith(new object[] { AppResources.RecordCountTipsFormatter.FormatWith(new object[] { count, name }) }), new object[0]);
});
};
if ((this.searchingConditionForAssociatedItemsForCurrentViewAccount.DataType == AssociatedItemType.All) || (this.searchingConditionForAssociatedItemsForCurrentViewAccount.DataType == AssociatedItemType.Transcations))
{
IQueryable<AccountItem> source = from p in ViewModelLocator.AccountItemViewModel.AccountBookDataContext.AccountItems
where p.AccountId == itemCompareToCurrent.Id
select p;
if (this.searchingConditionForAssociatedItemsForCurrentViewAccount.SearchingScope != SearchingScope.All)
{
source = from p in source
where (p.CreateTime.Date > this.searchingConditionForAssociatedItemsForCurrentViewAccount.StartDate.Value.Date) && (p.CreateTime.Date <= this.searchingConditionForAssociatedItemsForCurrentViewAccount.EndDate.Value.Date)
select p;
}
source = from p in source
orderby p.Type descending
select p into p
orderby p.CreateTime.Date descending
select p;
num = source.Count<AccountItem>();
action(num, AppResources.SelectAccountItemsLabel);
using (System.Collections.Generic.List<DateTime>.Enumerator enumerator = (from p in source select p.CreateTime.Date).Distinct<System.DateTime>().ToList<System.DateTime>().GetEnumerator())
{
System.DateTime item;
while (enumerator.MoveNext())
{
item = enumerator.Current;
GroupByCreateTimeAccountItemViewModel agvm = new GroupByCreateTimeAccountItemViewModel(item);
((System.Collections.Generic.IEnumerable<AccountItem>)(from p in source
where p.CreateTime.Date == item.Date
select p)).ForEach<AccountItem>(delegate(AccountItem x)
{
AccountItem item1 = new AccountItem
{
Account = x.Account,
Money = x.Money,
CreateTime = x.CreateTime,
Category = x.Category,
CategoryId = x.CategoryId,
Description = x.Description,
Id = x.Id,
State = x.State,
PageNameGetter = "AccountItems",
Type = x.Type,
TypeInfo = LocalizedStrings.GetLanguageInfoByKey(x.Type.ToString())
};
if (x.Type == ItemType.Expense)
{
item1.Money = -x.Money;
}
item1.SecondInfo = x.NameInfo;
item1.ThirdInfo = x.Description;
agvm.Add(item1);
});
container.Add(agvm);
}
}
}
if ((this.searchingConditionForAssociatedItemsForCurrentViewAccount.DataType == AssociatedItemType.All) || (this.searchingConditionForAssociatedItemsForCurrentViewAccount.DataType == AssociatedItemType.TransferingAccount))
{
IQueryable<TransferingItem> queryable2 = from p in ViewModelLocator.TransferingHistoryViewModel.AccountBookDataContext.TransferingItems
where (p.ToAccountId == itemCompareToCurrent.Id) || (p.FromAccountId == itemCompareToCurrent.Id)
select p;
if (this.searchingConditionForAssociatedItemsForCurrentViewAccount.SearchingScope != SearchingScope.All)
{
queryable2 = from p in queryable2
where (p.TransferingDate.Date > this.searchingConditionForAssociatedItemsForCurrentViewAccount.StartDate.Value.Date) && (p.TransferingDate.Date <= this.searchingConditionForAssociatedItemsForCurrentViewAccount.EndDate.Value.Date)
select p;
}
queryable2 = from p in queryable2
orderby p.TransferingDate.Date descending
select p;
num = queryable2.Count<TransferingItem>();
string exchange = AppResources.TransferingAccount;
action(num, exchange);
using (System.Collections.Generic.List<DateTime>.Enumerator enumerator2 = (from p in queryable2 select p.TransferingDate.Date).Distinct<System.DateTime>().ToList<System.DateTime>().GetEnumerator())
{
System.Func<GroupByCreateTimeAccountItemViewModel, Boolean> predicate = null;
System.DateTime item;
while (enumerator2.MoveNext())
{
item = enumerator2.Current;
if (predicate == null)
{
predicate = p => p.Key.Date == item.Date;
}
GroupByCreateTimeAccountItemViewModel agvm = container.FirstOrDefault<GroupByCreateTimeAccountItemViewModel>(predicate);
bool flag = false;
if (agvm == null)
//.........这里部分代码省略.........