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


C# IEnumerable.Last方法代码示例

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


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

示例1: BuildLastSeason

        private IList<TripleExponentialEntry> BuildLastSeason(IList<TripleExponentialEntry> currSeason,
                                                              IEnumerable<DataEntry> dataEntries, int currPeriod)
        {
            //building the last season is similar to NextSeason, but uses the same Ft and Tt once calculated for the first entry.
            var currentFt = currSeason.Last().Ft;
            var currentTt = currSeason.Last().Tt;
            double currentSt = currSeason.Last().St, lastSt = currSeason.Last().St;
            var lastActual = dataEntries.Last().Value;
            IList<TripleExponentialEntry> newSeason = new List<TripleExponentialEntry>();

            currentFt = (_alpha*(lastActual/lastSt)) + ((1 - _alpha)*(currentTt + currentFt));
            currentTt = (_beta*(currentFt - currSeason.Last().Ft)) + ((1 - _beta)*currentTt);

            for (var currSeasonIndex = 1; currSeasonIndex <= _periodsPerSeason; currSeasonIndex++)
            {
                var lastPeriodActual =
                    dataEntries.ElementAt((currPeriod + currSeasonIndex) - _periodsPerSeason - 2).Value;
                var lastPeriodFt = currSeason.ElementAt(currSeasonIndex - 1).Ft;
                var lastPeriodSt = currSeason.ElementAt(currSeasonIndex - 1).St;

                currentSt = (_gamma*(lastPeriodActual/lastPeriodFt)) + ((1 - _gamma)*lastPeriodSt);

                newSeason.Add(new TripleExponentialEntry
                    {
                        Ft = currentFt,
                        Tt = currentTt,
                        St = currentSt,
                        Forecast = (currentFt + (currentTt*currSeasonIndex))*currentSt
                    });
            }

            return newSeason;
        }
开发者ID:klaforce,项目名称:Silas,代码行数:33,代码来源:TripleExponentialSmoothingStrategy.cs

示例2: Verify

// ReSharper restore InconsistentNaming
#pragma warning restore 169

        static void Verify(IEnumerable<Tuple<string, int>> tuples, string item1, int item2)
        {
            tuples.Count().ShouldEqual(item2);
            tuples.First().Item1.ShouldEqual("I");
            tuples.First().Item2.ShouldEqual(1);
            tuples.Last().Item1.ShouldEqual(item1);
            tuples.Last().Item2.ShouldEqual(item2);
        }
开发者ID:TerryHughes,项目名称:Puzzles,代码行数:11,代码来源:BuildSpecifications.cs

示例3: DistanceBetweenLineSegments

        public static double DistanceBetweenLineSegments(IEnumerable<Coordinate> linesegment1, IEnumerable<Coordinate> linesegment2)
        {
            double perpendicularDist =  WEIGHT_PERPENIDCULAR * perpendicularDistance (linesegment1.First(), linesegment1.Last(), linesegment2.First(), linesegment2.Last());
            double parallelDist = WEIGHT_PARALLEL * parallelDistance (linesegment1, linesegment2);
            double angleDist = WEIGHT_ANGLE * angleDistance(linesegment1.First(), linesegment1.Last(), linesegment2.First(), linesegment2.Last());

            Console.WriteLine("PerpendicularDistance: " + perpendicularDist);
            Console.WriteLine("ParallelDistance: " + parallelDist);
            Console.WriteLine("AngleDistance: " + angleDist);

            return perpendicularDist + parallelDist + angleDist;
        }
开发者ID:leo-labs,项目名称:VisualTraclus,代码行数:12,代码来源:Algorithm.cs

示例4: ComposeUri

        public string ComposeUri(string baseUri, string location, object[] functionParameters, IEnumerable<KeyValuePair<string, string>> queryDictionary)
        {
            //Part 1 the basics http://thing.com/base/ + the nouns "/test"
            var part1 = (baseUri != null ? baseUri + "/" : "") + location;
            //Part 2 the parameters passed to the function call that aren't needed for the
            //output editor.
            var part2 = functionParameters == null || !functionParameters.Any()
                            ? ""
                            : "/" + functionParameters.Aggregate ((l, r) => l + "/" + r) + "/";
            //Part 3 the querystring
            var part3 = "";

            if (queryDictionary != null && queryDictionary.Any())
            {
                part3 += "?";
                foreach (var element in queryDictionary)
                {
                    if (element.Equals (queryDictionary.Last ()))
                        part3 += element.Key + "=" + element.Value;
                    else
                        part3 += element.Key + "=" + element.Value + "&";
                }
            }

            return part1 + part2 + part3;
        }
开发者ID:albertjan,项目名称:houses,代码行数:26,代码来源:RunningTotal.cs

示例5: GetGeoForPointByTime

        /// <summary>
        /// Get coords and altitude for point by it time and track
        /// </summary>
        /// <param name="pointTimeGTC">time for point</param>
        /// <param name="track">track</param>
        /// <returns>geo information for point</returns>
        public GeoData? GetGeoForPointByTime(DateTime pointTimeGTC, IEnumerable<GeoData> track)
        {
            if (pointTimeGTC > track.Last().CreatingDate)
                return null;
            if (pointTimeGTC < track.First().CreatingDate)
                return null;
            var trackArray = track.OrderBy(el=> el.CreatingDate).ToArray();
            for (int i = 0; i < trackArray.Length - 1; i++)
            {
                var before = trackArray[i];
                var after = trackArray[i + 1];
                if (after.CreatingDate.Ticks == before.CreatingDate.Ticks)
                    continue;

                if (pointTimeGTC >= before.CreatingDate &&
                    pointTimeGTC <= after.CreatingDate)
                {
                    // acount real coords by time
                    var koef = (double)(pointTimeGTC.Ticks- before.CreatingDate.Ticks)
                        / (double)(after.CreatingDate.Ticks - before.CreatingDate.Ticks);
                    return new GeoData()
                    {
                        Latitude = getRatioValue(before.Latitude, after.Latitude, koef),
                        Longitude = getRatioValue(before.Longitude, after.Longitude, koef),
                        Altitude = getRatioValue(before.Altitude, after.Altitude, koef),
                        CreatingDate = pointTimeGTC
                    };
                }
            }
            return null;
        }
开发者ID:TyurinaMariya,项目名称:EXIFPhotoEditor,代码行数:37,代码来源:GeoDataWorker.cs

示例6: PackageInfo

        IPackageInfo PackageInfo(IEnumerable<IPackageInfo> packageInfos)
        {
            if (Version != null)
                return packageInfos.OrderByDescending(x => x.Version).FirstOrDefault(x => x.Version.Major.Equals(Version.Major) && x.Version.Major.Equals(Version.Major));

            return packageInfos.Last();
        }
开发者ID:carcer,项目名称:openwrap,代码行数:7,代码来源:ViewWrapCommand.cs

示例7: CompileNullGuard

        Expression CompileNullGuard(IEnumerable<Expression> progression) {
            var last = progression.Last();
            var lastType = last.Type;

            if(!_guardNulls)
                return last;

            Expression allTests = null;

            foreach(var i in progression) {
                if(i == last)
                    break;

                var type = i.Type;
                if(!Utils.CanAssignNull(type))
                    continue;

                var test = Expression.Equal(i, Expression.Constant(null, type));
                if(allTests == null)
                    allTests = test;
                else
                    allTests = Expression.OrElse(allTests, test);
            }

            return Expression.Condition(
                allTests,
                Expression.Constant(Utils.GetDefaultValue(lastType), lastType),
                last
            );
        }
开发者ID:DevExpress,项目名称:DevExtreme.AspNet.Data,代码行数:30,代码来源:ExpressionCompiler.cs

示例8: ExternVariableToken

 public ExternVariableToken(Token parent, Scope scope, IEnumerable<Token> tokens, Token dataTypeToken, IEnumerable<WordToken> nameTokens)
     : base(parent, scope, new Span(tokens.First().Span.Start, tokens.Last().Span.End))
 {
     _tokens = tokens.ToArray();
     _dataTypeToken = dataTypeToken;
     _nameTokens = nameTokens.ToArray();
 }
开发者ID:cmrazek,项目名称:ProbeNpp,代码行数:7,代码来源:ExternVariableToken.cs

示例9: buildMessage

        private static string buildMessage(string address, IEnumerable<INetwork> networks)
        {
            StringBuilder result = new StringBuilder();

            result.Append("\"");
            result.Append(address);
            result.Append("\"");
            result.Append(" could refer to multiple devices: ");

            if (networks == null || !networks.Any())
            {
                result.Append("(no devices given)");
            }
            else
            {
                result.Append("{");
                //TODO: use TextUtilities
                foreach (var network in networks)
                {
                    result.Append("\"");
                    result.Append(network.Name);
                    result.Append("\"");

                    if (network != networks.Last())
                    {
                        result.Append(", ");
                    }
                }
                result.Append("}");
            }

            return result.ToString();
        }
开发者ID:Mavtak,项目名称:roomie,代码行数:33,代码来源:MultipleMatchingNetworksException.cs

示例10: MiniUiListToJson

 /// <summary>
 /// 专门生成为MiniUi生成json数据(List->json)
 /// </summary>
 /// <typeparam name="T">泛型</typeparam>
 /// <param name="list">实现了Ilist接口的list</param>
 /// <param name="total">记录总数</param>
 /// <param name="paramMaxMin">这里放排序的参数例如,string para=""maxAge":37,"avgAge":27,"minAge":24"</param>
 /// <returns>返回json数据</returns>
 public static string MiniUiListToJson(IEnumerable<SystemLog> SystemLogInfo, int total, string paramMaxMinAvg)
 {
     StringBuilder Json = new StringBuilder();
     Json.Append("{\"total\":" + total + ",\"data\":");
     Json.Append("[");
     foreach (SystemLog Info in SystemLogInfo)
     {
         Json.Append("{");
         Json.Append("\"Id\":\"" + Info.Id + "\"");
         Json.Append(",");
         Json.Append("\"Title\":\"" + Info.Title + "\"");
         Json.Append(",");
         Json.Append("\"AddTime\":\"" + Info.AddTime.Value.GetDateTimeFormats('s')[0].ToString() + "\"");
         Json.Append(",");
         Json.Append("\"Url\":\"" + Info.Url + "\"");
         Json.Append(",");
         Json.Append("\"UserName\":\"" + Info.UserName + "\"");
         Json.Append("}");
         if (Info != SystemLogInfo.Last())
         {
             Json.Append(",");
         }
     }
     Json.Append("]}");
     return Json.ToString();
 }
开发者ID:rogerxing90,项目名称:AHome,代码行数:34,代码来源:SystemLogBLL.cs

示例11: Forecast

        public ForecastEntry Forecast(IEnumerable<DataEntry> dataEntries, int period, dynamic strategyParameters)
        {
            if (period - 1 < 0)
                return null;

            double alpha = strategyParameters.Alpha;
            double beta = strategyParameters.Beta;
            double value;

            if (dataEntries.Count() < 3 || period < 3)
                value = dataEntries.ElementAt(0).Value;
            else if (dataEntries.Count() > 1 && period <= dataEntries.Count() + 1)
                value = GenerateForecast(3, period, alpha, beta, dataEntries, dataEntries.First().Value, 0);
            else
                value = GenerateForecast(3, dataEntries.Count() + 1, alpha, beta, dataEntries, dataEntries.First().Value,
                                         0);

            return new ForecastEntry
                {
                    Period = period,
                    DataEntry = period > dataEntries.Count() ? dataEntries.Last() : dataEntries.ElementAt(period - 1),
                    ForecastValue = value,
                    ConfidenceIntervalLow = value,
                    ConfidenceIntervalHigh = value,
                    IsHoldout = period > dataEntries.Count()*0.7 //holdout data is always 70 percent
                };
        }
开发者ID:klaforce,项目名称:Silas,代码行数:27,代码来源:DoubleExponentialSmoothingStrategy.cs

示例12: CalculatePath

        private static void CalculatePath(IEnumerable<int> indices)
        {
            double path = 0;
            int prev = -1;

            foreach (var current in indices)
            {
                if (prev > -1)
                {
                    path += Distance(points[prev], points[current]);
                }

                prev = current;
            }

            var last = points[indices.Last()];
            var first = points[indices.First()];

            path += Distance(last, first);

            if (path < minLength)
            {
                minLength = path;
                shortestPath = PathToString(indices);
            }
        }
开发者ID:nikoudel,项目名称:tsp,代码行数:26,代码来源:Program.cs

示例13: buildMessage

        private static string buildMessage(string address, IEnumerable<IDeviceState> devices)
        {
            var result = new StringBuilder();

            result.Append("\"");
            result.Append(address);
            result.Append("\"");
            result.Append(" could refer to multiple devices: ");

            if (devices == null || !devices.Any())
            {
                result.Append("(no devices given)");
            }
            else
            {
                result.Append("{");
                foreach (var device in devices)
                {
                    result.Append("\"");
                    result.Append(device.Name);
                    result.Append("\"");

                    if (device != devices.Last())
                    {
                        result.Append(", ");
                    }
                }
                result.Append("}");
            }

            return result.ToString();
        }
开发者ID:Mavtak,项目名称:roomie,代码行数:32,代码来源:MultipleMatchingDevicesException.cs

示例14: Forecast

        public ForecastEntry Forecast(IEnumerable<DataEntry> dataEntries, int period, dynamic strategyParameters)
        {
            if (period - 1 < 0)
                return null;

            int numberOfPeriods = strategyParameters.PeriodCount;

            if (numberOfPeriods > dataEntries.Count())
                throw new ArgumentException("The number of periods can not be greater than the number of entries.");

            double value;

            if (dataEntries.Count() == 1 || period == 1)
                value = dataEntries.ElementAt(0).Value;
            else if (period < numberOfPeriods)
                value = dataEntries.ElementAt(period - 1).Value;
            else if (dataEntries.Count() > 1 && period <= dataEntries.Count() + 1)
                value =
                    dataEntries.Take(period - 1).Reverse().Take(numberOfPeriods).Reverse().Sum(entry => (entry.Value))/
                    numberOfPeriods;
            else
                value = dataEntries.Reverse().Take(numberOfPeriods).Reverse().Sum(entry => (entry.Value))/
                        numberOfPeriods;

            return new ForecastEntry
                {
                    Period = period,
                    DataEntry = period > dataEntries.Count() ? dataEntries.Last() : dataEntries.ElementAt(period - 1),
                    ForecastValue = value,
                    ConfidenceIntervalLow = value,
                    ConfidenceIntervalHigh = value,
                    IsHoldout = period > dataEntries.Count()*0.7 //holdout data is always 70 percent
                };
        }
开发者ID:klaforce,项目名称:Silas,代码行数:34,代码来源:MovingAverageStrategy.cs

示例15: WriteCalls

        private static void WriteCalls(IEnumerable<CallInfo> callInfos, IOutputWriter writer)
        {
            var lastCall = callInfos.Last();
            var numberOfDigitsInLastCallNumber = lastCall.NumberOfDigitsInCallNumber();
            
            foreach (var call in callInfos)
            {
                if (call.CallNumber > 1)
                {
                    writer.WriteLine();
                }

                writer.Write(call.CallNumber);
                writer.Write(": ");

                WriteSpaces(writer, numberOfDigitsInLastCallNumber - call.NumberOfDigitsInCallNumber());

                using (writer.Indent())
                {
                    writer.Write(call.StringRepresentation);
                }
                
                if (call.Repeat > 1)
                {
                    writer.Write(" repeated ");
                    writer.Write(call.Repeat);
                    writer.Write(" times");
                    writer.WriteLine();
                    writer.Write("...");
                }
            }
        }
开发者ID:NameOfTheDragon,项目名称:FakeItEasy,代码行数:32,代码来源:CallWriter.cs


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