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


C# List.First方法代码示例

本文整理汇总了C#中Entities.List.First方法的典型用法代码示例。如果您正苦于以下问题:C# List.First方法的具体用法?C# List.First怎么用?C# List.First使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Entities.List的用法示例。


在下文中一共展示了List.First方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: RefreshHierarchyPostCache

        private byte[] RefreshHierarchyPostCache(List<HierarchyPost> hierarchyPosts)
        {
            var serializedPosts = JsonConvert.SerializeObject(hierarchyPosts, new JsonSerializerSettings {DefaultValueHandling = DefaultValueHandling.Ignore});
            var gzippedPosts = Gzipper.Zip(serializedPosts);

            var root = hierarchyPosts.First();
            if (root.RootId != root.PostId)
            {
                throw new ArgumentException($"Can't refresh cache for Hierarchy post because the first post has value of RootId {root.RootId} and the PostId is {root.PostId}");
            }

            var key = root.RootId.ToString();
            var lastChangeTicks = DateTime.UtcNow.Ticks;
            var entries = new[]
                              {
                                  new HashEntry("Posts", gzippedPosts),
                                  new HashEntry("LastChangeTicks", lastChangeTicks),
                                  new HashEntry("Views", root.Views)
                              };
            _redis.GetDatabase().HashSet(key, entries, CommandFlags.FireAndForget);

            var memoryKeyValue = new Tuple<PostMetadata, byte[]>(
                new PostMetadata
                    {
                        LastChangeTicks = lastChangeTicks,
                        ViewsCount = root.Views
                    }, gzippedPosts);

            _memoryCache.Set(key, memoryKeyValue);

            return gzippedPosts;
        }
开发者ID:gdoron,项目名称:Forums,代码行数:32,代码来源:PostsCacher.cs

示例2: FindBookByTag

        /// <summary>
        /// Finds some book depending on function 
        /// </summary>
        /// <param name="function">Condition to find book</param>
        /// <returns>Book</returns>
        public Book FindBookByTag(Func<Book, bool> function)
        {
            Book result = null;

            try
            {
                if (function == null)
                {
                    logger.Error("Error while find book by tag");
                    throw new ArgumentNullException("Tag is null");
                }
                books = repository.LoadToList();
                result = books.First(function);
                logger.Info("Book was found successfully");
            }
            catch (Exception e)
            {
                logger.Info(e.Message);
                logger.Error(e.StackTrace);
            }

            return result;
        }
开发者ID:zzhukanton,项目名称:BSU.ASP1501.Day5.Zhuk,代码行数:28,代码来源:BookList.cs

示例3: Search

        public IEnumerable<KeyValuePair<int, string>> Search(string customerName)
        {
            if (string.IsNullOrEmpty(customerName) || string.IsNullOrWhiteSpace(customerName))
            {
                yield return new KeyValuePair<int, string>();
            }

            var search = new CustomerSearch(new LevenshteinDistance());

            IEnumerable<KeyValuePair<int, string>> values = new List<KeyValuePair<int, string>>();
            if (_customerRespository.Persistence == Persistence.SQL)
            {
                values = _customerRespository.All.Select(i => new KeyValuePair<int, string>(i.Id, i.Name)).ToList();
            }
            else if (_customerRespository.Persistence == Persistence.Graph)
            {
                var graph = _customerRespository.GraphClient;

                values = graph.Cypher.Match("(p:Customer)").Return(p => p.As<CustomerGraph.Node>()).Results
                                     .Select(p => new KeyValuePair<int, string>((int)p.Id, p.Name));
            }

            foreach (var match in search.FindClosestMatches(customerName, values.Select(i => i.Value), 5))
            {
                yield return (new KeyValuePair<int, string>(values.First(c => c.Value == match).Key, match));
            }
        }
开发者ID:anderssonfilip,项目名称:CustomerManagement,代码行数:27,代码来源:CustomerController.cs

示例4: CalculateResultVector

        private static Double[] CalculateResultVector(List<Double[]> vectors)
        {
            List<Double> resultVector = new List<Double>();

            Int32 n = vectors.First().Length;

            for (Int32 i = 0; i < n; i++)
            {
                Double tmp = 0;
                for (Int32 j = 0; j < vectors.Count; j++)
                {
                    tmp += vectors.ToArray()[j][i];
                }

                resultVector.Add(tmp / vectors.Count);
            }

            return resultVector.ToArray();
        }
开发者ID:SenkaOlefir,项目名称:Project_MVC,代码行数:19,代码来源:JudgmentHelper.cs


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