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


C# IList.Max方法代码示例

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


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

示例1: SetMinMax

        public void SetMinMax(IList<Point> points)
        {
            if (_isMaxMinSet)
            {
                var minX = points.Min(point => point.X);
                MinX = minX < MinX ? minX : MinX;

                var maxX = points.Max(point => point.X);
                MaxX = maxX > MaxX ? maxX : MaxX;

                var minY = points.Min(point => point.Y);
                MinY = minY < MinY ? minY : MinY;

                var maxY = points.Max(point => point.Y);
                MaxY = maxY > MaxY ? maxY : MaxY;
            }
            else
            {
                MinX = points.Min(point => point.X);
                MaxX = points.Max(point => point.X);
                MinY = points.Min(point => point.Y);
                MaxY = points.Max(point => point.Y);
                _isMaxMinSet = true;
            }
            SetOriginPoint(GetDelta());
        }
开发者ID:tarakreddy,项目名称:ADAPT,代码行数:26,代码来源:DrawingUtil.cs

示例2: fillTagCounts

        /// <summary>
        /// Fill weight and url for each tag.
        /// </summary>
        /// <param name="tagCounts">The tags to fill.</param>
        private void fillTagCounts(IList<TagCount> tagCounts)
        {
            int maxCount = tagCounts.Max(t => t.Total);
            foreach (TagCount tagCount in tagCounts)
            {
                double count = (double)tagCount.Total;
                double percent = (count / maxCount) * 100;

                if (percent < 20)
                {
                    tagCount.Weight = 1;
                }
                else if (percent < 40)
                {
                    tagCount.Weight = 2;
                }
                else if (percent < 60)
                {
                    tagCount.Weight = 3;
                }
                else if (percent < 80)
                {
                    tagCount.Weight = 4;
                }
                else
                {
                    tagCount.Weight = 5;
                }

                tagCount.Url = UrlBuilder.GetTagUrl(tagCount.UrlSlug);
            }
        }
开发者ID:tommyenglish,项目名称:tommysblog,代码行数:36,代码来源:TagService.cs

示例3: Initialize

        public void Initialize()
        {
            _data = new List<StoredUser>
            {
                new StoredUser {Id = 1, Name = "William Parker", MetaData = "Researcher"},
                new StoredUser {Id = 2, Name = "Trudy Jones", MetaData = "Researcher"}
            };

            _mockSet = MockUtility.CreateAsyncMockDbSet(_data, u => u.Id);

            var mockContext = new Mock<IAutoSysContext>();
            mockContext.Setup(s => s.Users).Returns(_mockSet.Object);
            mockContext.Setup(s => s.Set<StoredUser>()).Returns(_mockSet.Object);
            mockContext.Setup(s => s.SaveChangesAsync()).Returns(Task.Run(() =>
            {
                // Increment user ids automatically based on existing ids in mock data 
                var max = _data.Max(u => u.Id);
                foreach (var user in _data.Where(u => u.Id == 0))
                {
                    user.Id = ++max;
                }
                return 1; // SaveChangesAsync returns number based on how many times it was called per default 
            }));

            _context = mockContext;
            _repository = new UserRepository(_context.Object);
        }
开发者ID:BDSA-2015,项目名称:AutosysProgram,代码行数:27,代码来源:UserRepositoryTests.cs

示例4: PadElementsInLines

 /// <summary>
 /// Converts a List of string arrays to a string where each element in each line is correctly padded.
 /// Make sure that each array contains the same amount of elements!
 /// - Example without:
 /// Title Name Street
 /// Mr. Roman Sesamstreet
 /// Mrs. Claudia Abbey Road
 /// - Example with:
 /// Title   Name      Street
 /// Mr.     Roman     Sesamstreet
 /// Mrs.    Claudia   Abbey Road
 /// <param name="lines">List lines, where each line is an array of elements for that line.</param>
 /// <param name="padding">Additional padding between each element (default = 1)</param>
 /// </summary>
 /// <see cref="http://stackoverflow.com/questions/4449021/how-can-i-align-text-in-columns-using-console-writeline"/> 
 public static string PadElementsInLines(IList<string[]> lines, int padding = 1)
 {
     // Calculate maximum numbers for each element accross all lines
     var numElements = lines[0].Length;
     var maxValues = new int[numElements];
     for (int i = 0; i < numElements; i++)
     {
         maxValues[i] = lines.Max(x => x[i].Length) + padding;
     }
     var sb = new StringBuilder();
     // Build the output
     bool isFirst = true;
     foreach (var line in lines)
     {
         if (!isFirst)
         {
             sb.AppendLine();
         }
         isFirst = false;
         for (int i = 0; i < line.Length; i++)
         {
             var value = line[i];
             // Append the value with padding of the maximum length of any value for this element
             sb.Append(value.PadRight(maxValues[i]));
         }
     }
     return sb.ToString();
 }
开发者ID:cherepets,项目名称:SeafClient,代码行数:43,代码来源:MiscUtils.cs

示例5: FeedResult

        private FeedResult FeedResult(IList<SyndicationItem> items)
        {
            var settings = Settings.GetSettings<FunnelWebSettings>();

            Debug.Assert(Request.GetOriginalUrl() != null, "Request.GetOriginalUrl() != null");

            var baseUri = Request.GetOriginalUrl();
            var feedUrl = new Uri(baseUri, Url.Action("Recent", "Wiki"));
            return new FeedResult(
                new Atom10FeedFormatter(
                    new SyndicationFeed(settings.SiteTitle, settings.SearchDescription, feedUrl, items)
                    {
                        Id = baseUri.ToString(),
                        Links =
                        {
                            new SyndicationLink(baseUri)
                            {
                                RelationshipType = "self"
                            }
                        },
                        LastUpdatedTime = items.Count() == 0 ? DateTime.Now : items.First().LastUpdatedTime
                    }), items.Max(i => i.LastUpdatedTime.LocalDateTime))
            {
                ContentType = "application/atom+xml"
            };
        }
开发者ID:nategreenwood,项目名称:nategreenwood.com,代码行数:26,代码来源:FeedController.cs

示例6: Initialize

        public void Initialize()
        {
            _data = new List<StoredProtocol>
            {
                new StoredProtocol {Id = 1, StudyName = "StudyName" }, // TODO add pseudo data 
                new StoredProtocol {Id = 2,  StudyName = "StudyName" }
            };

            _mockSet = MockUtility.CreateAsyncMockDbSet(_data, u => u.Id);

            var mockContext = new Mock<IAutoSysContext>();
            mockContext.Setup(s => s.Protocols).Returns(_mockSet.Object);
            mockContext.Setup(s => s.Set<StoredProtocol>()).Returns(_mockSet.Object);
            mockContext.Setup(s => s.SaveChangesAsync()).Returns(Task.Run(() =>
            {
                // Increment protocol ids automatically based on existing ids in mock data 
                var max = _data.Max(u => u.Id);
                foreach (var protocol in _data.Where(u => u.Id == 0))
                {
                    protocol.Id = ++max;
                }
                return 1; // SaveChangesAsync returns number based on how many times it was called per default 
            }));

            _context = mockContext;
            _repository = new ProtocolRepository(_context.Object);
        }
开发者ID:BDSA-2015,项目名称:AutosysProgram,代码行数:27,代码来源:ProtocolRepositoryTests.cs

示例7: Sort

        /// <summary>
        /// I feel like this way is a little bit more optimized since it saves space
        /// there is still the possibility of empty space beetwen min,max 
        /// but atleast it gets rid of the space from 0 to min
        /// 
        /// This will also work with negative numbers.
        /// </summary>
        public static int[] Sort(IList<int> data, int min, int max)
        {
            Contract.Ensures(data != null, "data cannot be a null pointer");
            Contract.Ensures(min == data.Min(), "wrong min submitted");
            Contract.Ensures(max == data.Max(), "wrong max submitted");

            int[] count = new int[(max - min) + 1];
            int[] sorted = new int[data.Count];

            // Add the elements in reverse order big --> small
            // NOTE: Could do key - min instead for order small --> big
            foreach (int key in data)
            {
                count[max - key] += 1;
            }

            // Transfer the temp array to the sorted array from small --> big
            int sortedIndex = data.Count - 1;
            for (int i = 0; i < count.Length; i++)
            {
                // How often did we have this number in the input?
                int number = max - i;
                for (int j = 0; j < count[i]; j++)
                {
                    sorted[sortedIndex--] = number;
                }
            }

            return sorted;
        }
开发者ID:jojojojochen,项目名称:Algorithm-Implementations,代码行数:37,代码来源:CountingSort.cs

示例8: GetMatchesForNextRound

        public IEnumerable<MatchModel> GetMatchesForNextRound(IList<PlayerModel> players, IList<MatchModel> previousMatches)
        {
            var matchesForNextRound = new List<MatchModel>();

            int round = previousMatches.Count == 0 ? 1 : previousMatches.Max(p => p.Round) + 1;

            List<PlayerModel> playerModels = _playersHelper.GetPlayersWithCalculatedRating(players, previousMatches)
                                                    .OrderByDescending(p => p.Rate)
                                                    .ToList();

            while (playerModels.Count > 0)
            {
                PlayerModel player = playerModels.First();
                playerModels.Remove(player);

                MatchModel matchModel = _matchesHelper.GetMatchModelForNextRound(player, playerModels, previousMatches);
                matchModel.Round = round;
                matchModel.Player1PlaysWhite = _playersHelper.PlayerCanPlayWithDefinedColor(player, ChessColor.White, previousMatches);
                matchModel.MatchStartTime = DateTime.Now;
                matchModel.Winner = new PlayerModel { PlayerId = SpecialPlayerIds.WinnerIdForGameWithUndefinedResult };

                playerModels.Remove(matchModel.Player2);
                matchesForNextRound.Add(matchModel);
            }

            return matchesForNextRound;
        }
开发者ID:RomanPanchenko,项目名称:Tournament,代码行数:27,代码来源:MatchGenerator.cs

示例9: ResolveSpecial

        private static int ResolveSpecial(IList<int> pancakes)
        {
            IList<int> newpancakes = new List<int>();

            int maxvalue = pancakes.Max();

            if (maxvalue == 1)
                return 1;

            int split = maxvalue / 2;
            int steps = pancakes.Count(n => n == maxvalue);

            foreach (int value in pancakes)
                if (value == maxvalue)
                    newpancakes.Add(value - split);
                else
                    newpancakes.Add(value);

            for (int k = 0; k < steps; k++)
                newpancakes.Add(split);

            int ncount1 = Resolve(newpancakes);

            return steps + Resolve(newpancakes);
        }
开发者ID:ajlopez,项目名称:TddRocks,代码行数:25,代码来源:Solver.cs

示例10: ProjectRepository

        public ProjectRepository(IList<Project> projects)
        {
            this.projects = projects;

            if (projects.Count > 0)
                this.maxid = projects.Max(p => p.Id);
        }
开发者ID:ajlopez,项目名称:TddRocks,代码行数:7,代码来源:ProjectRepository.cs

示例11: CalculateDeceitfulWar

        public int CalculateDeceitfulWar(IList<double> first, IList<double> second)
        {
            if (first.Count == 0)
                return 0;

            double min1 = first.Min();
            double min2 = second.Min();
            bool win = false;

            double play1;
            double play2;

            if (min1 < min2)
            {
                play1 = min1;
                play2 = second.Max();
            }
            else
            {
                play1 = min1;
                play2 = min2;
                win = true;
            }

            var newfirst = first.Where(n => n != play1).ToList();
            var newsecond = second.Where(n => n != play2).ToList();

            return CalculateDeceitfulWar(newfirst, newsecond) + (win ? 1 : 0);
        }
开发者ID:ajlopez,项目名称:TddRocks,代码行数:29,代码来源:Strategy.cs

示例12: Render

        /// <summary>
        /// Convert numbers to spark chart strings.
        /// </summary>
        /// <param name="data">List or Array of numbers</param>
        /// <returns>empty string if <paramref name="data"/>is <code>null</code> or empty.</returns>
        public static String Render(IList<double> data)
        {
            var ticks = TickProvider.Ticks;

            if (data == null || data.Count == 0)
                return string.Empty;

            char[] res = new char[data.Count()];

            double min = data.Min();
            double max = data.Max();
            double step = (max - min) / (ticks.Length - 1);
            if (step.Equals(0d)) step = 1;

            for (var i = 0; i < data.Count(); i++)
            {
                var val = data[i];
                double d = (val - min)/step;

                // if it's 10^-10 close to its rounded, round; floor otherwise
                int tick = (int) ((Math.Abs(Math.Round(d) - d) < 1e-10) ? Math.Round(d) : Math.Floor((val - min) / step));
                res[i] = ticks[tick];
            }
            return new string(res);
        }
开发者ID:andrijac,项目名称:Spark.NET,代码行数:30,代码来源:Spark.cs

示例13: Hull

        /// <summary>
        /// Initializes a new instance of the <see cref="Hull"/> class.
        /// </summary>
        /// <param name="points">The points.</param>
        public Hull(IList<Vector2> points)
        {
            var numVertices = points.Count * 2;
            var numTris = numVertices - 2;
            var numIndicies = numTris * 3;

            this.vertices = new HullVertex[numVertices];
            this.indices = new int[numIndicies];
            this.scale = Vector2.One;

            for (var i = 0; i < points.Count; i++)
            {
                var p1 = points[i];
                var p2 = points[(i + 1) % points.Count];

                var normal = (p2 - p1).Clockwise();

                normal.Normalize();

                this.vertices[i * 2] = new HullVertex(p1, normal, new Color(0, 0, 0, 0.1f));
                this.vertices[(i * 2) + 1] = new HullVertex(p2, normal, new Color(0, 0, 0, 0.1f));
            }

            for (var i = 0; i < numTris; i++)
            {
                this.indices[i * 3] = 0;
                this.indices[(i * 3) + 1] = i + 1;
                this.indices[(i * 3) + 2] = i + 2;
            }

            this.RadiusSquared = points.Max(x => x.LengthSquared());
        }
开发者ID:AndrewHackler,项目名称:shooter,代码行数:36,代码来源:Hull.cs

示例14: GetIntervalsForNumberOfClasses

        /// <summary>
        /// Generates intervals based on type, numberOfClasses and values.
        /// </summary>
        /// <param name="values"></param>
        /// <param name="type"></param>
        /// <param name="numberOfClasses"></param>
        /// <returns></returns>
        public static IList<Interval> GetIntervalsForNumberOfClasses(IList<Single> values, QuantityThemeIntervalType type, int numberOfClasses)
        {
            int index = 0;
            var intervals = new List<Interval>();
            var lowValue = values.Min();
            var highValue = values.Max();
            if (type == QuantityThemeIntervalType.NaturalBreaks)
            {
                ArrayList.Adapter((IList)values).Sort(); // performance, works 20% faster than layerAttribute.AttributeValues.Sort();
            }

            for (int i = 0; i < numberOfClasses; i++)
            {
                float intervalMin;
                float intervalMax;

                if (type == QuantityThemeIntervalType.EqualIntervals)
                {

                    intervalMin = lowValue + i * ((highValue - lowValue) / numberOfClasses);
                    intervalMax = lowValue + (i + 1) * ((highValue - lowValue) / numberOfClasses);
                }
                else
                {
                    intervalMin = Convert.ToSingle(values[index]);
                    index = (int)Math.Ceiling((double)(i + 1) / numberOfClasses * (values.Count - 1));
                    intervalMax = Convert.ToSingle(values[index]);
                }

                var interval = new Interval(intervalMin, intervalMax);
                intervals.Add(interval);
            }

            return intervals;
        }
开发者ID:lishxi,项目名称:_SharpMap,代码行数:42,代码来源:ThemeFactoryHelper.cs

示例15: DisplayStats

        static void DisplayStats(IList<Response> responses)
        {
            if (!responses.Any())
            {
                return;
            }

            var average = responses.Average(x => (x.EndUtc - x.StartUtc).TotalMilliseconds);
            ClearLine();
            Console.WriteLine("Average time: {0} ms", Convert.ToInt32(average));

            var min = responses.Min(x => x.StartUtc);
            var max = responses.Max(x => x.EndUtc);
            var count = responses.Count;
            var timespan = Convert.ToInt32((max - min).TotalMilliseconds);
            timespan = timespan == 0 ? 0 : timespan / 1000;
            var rps = timespan == 0 ? 0 : count / timespan;

            ClearLine();
            Console.WriteLine("Performance: {0} rps ({1} reqs in {2})", Convert.ToInt32(rps), responses.Count, timespan);

            ClearLine();
            Console.WriteLine("Threads: {0}", responses.Select(x => x.TaskId).Distinct().Count());

            ClearLine();
            Console.WriteLine("Errors: {0}", responses.Count(x => !x.Success));
        }
开发者ID:sebastienros,项目名称:LoadTest,代码行数:27,代码来源:Program.cs


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