当前位置: 首页>>代码示例>>C#>>正文


C# System.Collections.Generic.List.FirstOrDefault方法代码示例

本文整理汇总了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;
 }
开发者ID:Adilson,项目名称:Craig-s-Utility-Library,代码行数:27,代码来源:CacheTables.cs

示例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)
//.........这里部分代码省略.........
开发者ID:RukaiYu,项目名称:TinyMoneyManager.WP8,代码行数:101,代码来源:AccountViewModel.cs


注:本文中的System.Collections.Generic.System.Collections.Generic.List.FirstOrDefault方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。