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


C# IEnumerable.Count方法代码示例

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


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

示例1: GetJsonForAoutPayment

        internal static object GetJsonForAoutPayment(IEnumerable<Payment> payment, int page)
        {
            if (payment == null)
            {
                return string.Empty;
            }

            var result = new
            {
                total = payment.Count(),
                page,
                records = payment.Count(),
                rows = payment.OrderByDescending(c => c.PaymentDate).Select(x => new
                {
                    id = x.Id,
                    cell = new[]
                    {
                        x.PaymentDate.ToString("dd.MM.yyyy"),
                        x.FromAccount.CardNumber.ToString(),
                        x.ToAccount.Description,
                        x.TotalAmount.ToString(),
                        x.Currency.Abbreveature
                    }
                })
            };

            return result;
        }
开发者ID:hackersdelight,项目名称:BVP-banking,代码行数:28,代码来源:JSonConverters.cs

示例2: CreateProgressMessage

		ProgressMonitorStatusMessage CreateProgressMessage (IEnumerable<ReinstallPackageAction> actions)
		{
			if (actions.Count () == 1) {
				return ProgressMonitorStatusMessageFactory.CreateRetargetingSinglePackageMessage (actions.First ().PackageId);
			}
			return ProgressMonitorStatusMessageFactory.CreateRetargetingPackagesInProjectMessage (actions.Count ());
		}
开发者ID:pabloescribanoloza,项目名称:monodevelop,代码行数:7,代码来源:ReinstallAllPackagesInProjectHandler.cs

示例3: AccountDictionaryRecordConditionAdd

        /// <summary>
        /// Add AccountDictionaryRecordConditions to database
        /// </summary>
        /// <param name="instances">AccountDictionaryRecordCondition instance array</param>
        /// <param name="accountDictionaryRecord">AccountDictionaryRecord instance for instances</param>
        /// <param name="saveAfterInsert">Save database after insertion</param>
        /// <param name="waitUntilSaving">Wait until saving</param>
        public void AccountDictionaryRecordConditionAdd(IEnumerable<AccountDictionaryRecordCondition> instances, AccountDictionaryRecord accountDictionaryRecord, bool saveAfterInsert = true, bool waitUntilSaving = true)
        {
            try
            {
                if (instances == null)
                    throw new ArgumentNullException("instances");
                if (accountDictionaryRecord == null)
                    throw new ArgumentNullException("accountDictionary");
                instances = instances.Where(i => i != null).ToArray();
                try
                {
                    foreach (var i in instances)
                        if (i.DictionaryRecord != accountDictionaryRecord)
                            i.DictionaryRecord = accountDictionaryRecord;

                    this.Context.AccountDictionaryRecordConditions.AddRange(instances);
                    if (saveAfterInsert)
                        this.SaveChanges(waitUntilSaving);
                }
                catch (Exception ex)
                {
                    var e = new Exception(ex.Message, ex);
                    for (int i = 0; i < instances.Count();i++)
                        e.Data.Add(string.Format("instance_{0}", i), instances.ElementAt(i).ToString());
                    throw e;
                }
            }
            catch (Exception ex)
            {
                Helpers.Log.Add(ex, string.Format("Repository.AccountDictionaryRecordConditionAdd(instances=[{0}],saveAfterInsert={1},waitUntilSaving={2})", instances == null ? "NULL" : instances.Count().ToString(), saveAfterInsert, waitUntilSaving));
                throw;
            }
        }
开发者ID:kblc,项目名称:Royalty,代码行数:40,代码来源:AccountDictionaryRecordCondition.cs

示例4: ScrobbleAsync

        public static IAsyncResult ScrobbleAsync(IEnumerable<TrackScrobble> tracks, Action<IEnumerable<TrackScrobble>> callback)
        {
            if (tracks.Count() > 50) throw new ArgumentException("Last.fm supports a maximum of 50 tracks");
            if (tracks.Count() == 0) return null;

            var parameters = new Dictionary<string, string>();
            parameters.Add("method", "track.scrobble");

            var i = 0;
            foreach (var trackScrobble in tracks)
            {
                var tp = trackScrobble.track.GetParametersDictionary(i);
                foreach (var p in tp)
                {
                    parameters.Add(p.Key, p.Value);
                }
                parameters.Add("timestamp[" + i + "]", trackScrobble.timestamp.ToString());
                i++;
            }

            return LfmServiceProxy.GetResponseAsync(parameters, (doc) =>
            {
                if (callback != null)
                    callback(tracks);

                var info = doc.Element("lfm").Element("scrobbles");
                var acc = info.Attribute("accepted").Value;
                var rej = info.Attribute("ignored").Value;

                Logger.LogMessage(string.Format("Batch scrobble info: accepted {0} tracks, ignored {1} tracks", acc, rej));
            });
        }
开发者ID:MrSm1th,项目名称:lastfm,代码行数:32,代码来源:Track.cs

示例5: Distribute

        public IEnumerable<StudyTask> Distribute(IEnumerable<User> users, IEnumerable<StudyTask> tasks)
        {
            var userList = users.ToList();
            var sublists = new List<List<StudyTask>>();

            var rangeSize = tasks.Count()/userList.Count();
            var additionalItems = tasks.Count()%userList.Count();
            var index = 0;

            while (index < tasks.Count())
            {
                var currentRangeSize = rangeSize + (additionalItems > 0 ? 1 : 0);
                sublists.Add(tasks.ToList().GetRange(index, currentRangeSize));
                index += currentRangeSize;
                additionalItems--;
            }

            var ui = 0;

            foreach (var sublist in sublists)
            {
                foreach (var task in sublist)
                {
                    task.DataFields.ForEach(d => d.UserData.Clear());
                    task.Users.Add(userList[ui]);
                    foreach (var dataField in task.DataFields)
                    {
                        dataField.UserData.Add(new UserData {UserId = userList[ui].ID});
                    }

                    yield return task;
                }
                ui++;
            }
        }
开发者ID:CruelMoney,项目名称:AutoSys,代码行数:35,代码来源:Distributors.cs

示例6: GetCentralPosition

        public static Position GetCentralPosition(IEnumerable<Position> geoCoordinates)
        {
            if (geoCoordinates.Count() == 1) {
                return geoCoordinates.Single ();
            }

            double x = 0;
            double y = 0;
            double z = 0;

            foreach (var geoCoordinate in geoCoordinates) {
                var latitude = geoCoordinate.Latitude * Math.PI / 180;
                var longitude = geoCoordinate.Longitude * Math.PI / 180;

                x += Math.Cos (latitude) * Math.Cos (longitude);
                y += Math.Cos (latitude) * Math.Sin (longitude);
                z += Math.Sin (latitude);
            }

            var total = geoCoordinates.Count();

            x = x / total;
            y = y / total;
            z = z / total;

            var centralLongitude = Math.Atan2 (y, x);
            var centralSquareRoot = Math.Sqrt (x * x + y * y);
            var centralLatitude = Math.Atan2 (z, centralSquareRoot);

            return new Position (
                centralLatitude * 180 / Math.PI,
                centralLongitude * 180 / Math.PI
            );
        }
开发者ID:harrysaggu,项目名称:xamarin-plugins,代码行数:34,代码来源:GeoHelper.cs

示例7: GetPublishedFileDetails

        static public bool GetPublishedFileDetails(IEnumerable<ulong> publishedFileIds, Action<bool, string> callback)
        {
            uint handle = HTTP.CreateHTTPRequest(HTTPMethod.POST, string.Format(m_requestFormat, "ISteamRemoteStorage", "GetPublishedFileDetails", 1));

            if (!HTTP.SetHTTPRequestGetOrPostParameter(handle, "itemcount", publishedFileIds.Count().ToString()))
            {
                MySandboxGame.Log.WriteLine(string.Format("HTTP: failed to set parameter '{0}' = '{1}'", "itemcount", publishedFileIds.Count().ToString()));
                return false;
            }

            int i = 0;
            foreach(var id in publishedFileIds)
            {
                if (!HTTP.SetHTTPRequestGetOrPostParameter(handle, string.Format("publishedfileids[{0}]", i), id.ToString()))
                {
                    MySandboxGame.Log.WriteLine(string.Format("HTTP: failed to set parameter '{0}' = '{1}'", string.Format("publishedfileids[{0}]", i), id.ToString()));
                    return false;
                }
                ++i;
            }

            if (!HTTP.SendHTTPRequest(handle, onRequestCompleted))
            {
                MySandboxGame.Log.WriteLine("HTTP: failed to send request");
                return false;
            }

            m_callbacks[handle] = callback;

            return true;
        }
开发者ID:ChristianHeinz71,项目名称:SpaceEngineers,代码行数:31,代码来源:MySteamWebAPI.cs

示例8: ToDto

 public static DT.Run ToDto(DA.Run source, bool includeBinaryValues, IEnumerable<DT.ValueName> valueNames) {
   if (source == null) return null;
   var dto = new DT.Run { Id = source.Id, Algorithm = Convert.ToDto(source.Algorithm), Problem = Convert.ToDto(source.Problem), CreatedDate = source.CreatedDate, ClientId = source.ClientId, UserId = source.UserId };
   dto.ParameterValues = source.Values.Where(x => x.ValueName.Category == DA.ValueNameCategory.Parameter && valueNames.Count(y => y.Name == x.ValueName.Name) > 0).Select(x => Convert.ToDto(x, includeBinaryValues)).ToArray();
   dto.ResultValues = source.Values.Where(x => x.ValueName.Category == DA.ValueNameCategory.Result && valueNames.Count(y => y.Name == x.ValueName.Name) > 0).Select(x => Convert.ToDto(x, includeBinaryValues)).ToArray();
   return dto;
 }
开发者ID:t-h-e,项目名称:HeuristicLab,代码行数:7,代码来源:Convert.cs

示例9: FilterMethodByParams

 /// <summary>
 /// Permet de filtrer sur les parametres d'une fonction pour les fonctions surchargées
 /// </summary>
 /// <param name="methods"></param>
 /// <param name="parameters"></param>
 /// <returns></returns>
 private static MethodInfo FilterMethodByParams(IEnumerable<MethodInfo> methods, IEnumerable<object> parameters)
 {
     if (parameters != null)
     {
         var paramsNull = parameters.Where(p => p.Equals(null));
         if (!paramsNull.Any())
         {
             IEnumerable<Type> types = parameters.Select(param => param.GetType());
             var methodsFiltered = methods.Where(m => m.GetParameters().Count() == parameters.Count());
             if (methodsFiltered.Any())
             {
                 foreach (var methodInfo in methodsFiltered)
                 {
                     if (types.SequenceEqual(methodInfo.GetParameters().Select(p => p.ParameterType).ToList()))
                     {
                         return methodInfo;
                     }
                 }
             }
         }
         else
         {
             var methodsFiltered = methods.Where(m => m.GetParameters().Count() == parameters.Count());
             if (methodsFiltered.Any())
             {
                 return methodsFiltered.First();
             }
         }
     }
     return null;
 }
开发者ID:ToliConsulting,项目名称:navegar,代码行数:37,代码来源:TypeExtensions.cs

示例10: DocumentFilenameWithIncrement

        public static string DocumentFilenameWithIncrement(string originalFilename, IEnumerable<ClientDocument> documents)
        {
            var originalFilenameWithoutExtention = originalFilename.Substring(0, originalFilename.LastIndexOf("."));
            var extension = originalFilename.Substring(originalFilename.LastIndexOf("."));
            var filenameFormat = originalFilenameWithoutExtention + "{0}" + extension;
            var formattedFilename = "";
            var filename = originalFilename;
            var duplicateFilename = false;
            var newFilenameCreated = false;
            int i = 1;

            if (documents.Count(d => d.Filename == filename) > 0)
                duplicateFilename = true;

            while (duplicateFilename && !newFilenameCreated)
            {
                formattedFilename = string.Format(filenameFormat, " (" + (i++) + ")");

                if (documents.Count(d => d.Filename == formattedFilename) == 0)
                {
                    filename = formattedFilename;
                    newFilenameCreated = true;
                }
            }

            return filename;
        }
开发者ID:jserna-arl,项目名称:LIMSv2,代码行数:27,代码来源:AppLib.cs

示例11: createColumnParameterAssignments

        private static string createColumnParameterAssignments(
            IEnumerable<KeyValuePair<Column, StoredProcedureParameter>> columnsToParameters,
            string firstDelimiter,
            string delimiter,
            int indent)
        {
            StringBuilder stringBuilder = new StringBuilder();
            string indentString = string.Empty;
            for (int i = 0; i < indent; i++)
            {
                indentString = string.Format("{0}{1}", indentString, "\t");
            }

            int columnNameSize = 0;
            if (columnsToParameters.Count() > 1)
            {
                foreach (KeyValuePair<Column, StoredProcedureParameter> kv in columnsToParameters)
                {
                    if (kv.Key.Name.Length > columnNameSize)
                    {
                        columnNameSize = kv.Key.Name.Length;
                    }
                }
            }
            columnNameSize += 3;

            IEnumerator<KeyValuePair<Column, StoredProcedureParameter>> enumerator = columnsToParameters.GetEnumerator();
            if (enumerator.MoveNext())
            {
                KeyValuePair<Column, StoredProcedureParameter> current = enumerator.Current;
                string currentName = string.Format("[{0}]", current.Key.Name);
                stringBuilder = stringBuilder.AppendFormat("{0}{1}{2}= {3}{4}",
                    firstDelimiter,
                    currentName.PadRight(columnNameSize),
                    columnsToParameters.Count() > 1 ? "\t" : " ",
                    current.Value.Name,
                    Environment.NewLine);
            }

            while (enumerator.MoveNext())
            {
                KeyValuePair<Column, StoredProcedureParameter> current = enumerator.Current;
                string currentName = string.Format("[{0}]", current.Key.Name);
                stringBuilder = stringBuilder.AppendFormat("{0}{1}{2}{3}= {4}{5}",
                    indentString,
                    delimiter,
                    currentName.PadRight(columnNameSize),
                    columnsToParameters.Count() > 1 ? "\t" : " ",
                    current.Value.Name,
                    Environment.NewLine);
            }

            string str = stringBuilder.ToString();
            if (str.LastIndexOf(Environment.NewLine) > 0)
            {
                str = str.Remove(str.LastIndexOf(Environment.NewLine));
            }

            return str;
        }
开发者ID:rexwhitten,项目名称:MGenerator,代码行数:60,代码来源:CrudProcedureGenerator.cs

示例12: SelectLabels

        private async Task SelectLabels(IEnumerable<LabelModel> x)
        {
            //If nothing has changed, dont do anything...
            if (_originalLables != null && _originalLables.Count() == x.Count() && _originalLables.Intersect(x).Count() == x.Count())
            {
                ChangePresentation(new MvxClosePresentationHint(this));
                return;
            }
                
            if (SaveOnSelect)
            {
                try
                {
                    IsSaving = true;
                    var labels = x != null ? x.Select(y => y.Name).ToArray() : null;
                    var updateReq = this.GetApplication().Client.Users[Username].Repositories[Repository].Issues[Id].UpdateLabels(labels);
                    var newIssue = await this.GetApplication().Client.ExecuteAsync(updateReq);
                    Messenger.Publish(new IssueEditMessage(this) { Issue = newIssue.Data });
                }
                catch
                {
                    DisplayAlert("Unable to save labels! Please try again.");
                }
                finally
                {
                    IsSaving = false;
                }
            }
            else
            {
                Messenger.Publish(new SelectIssueLabelsMessage(this) { Labels = SelectedLabels.Items.ToArray() });
            }

            ChangePresentation(new MvxClosePresentationHint(this));
        }
开发者ID:GitWatcher,项目名称:CodeHub,代码行数:35,代码来源:IssueLabelsViewModel.cs

示例13: BuildTeachersTable

        /// <summary>
        /// BuildTeachersTable
        /// </summary>
        /// <param name="ws"></param>
        /// <param name="Teachers"></param>
        private static void BuildTeachersTable(ExcelWorksheet ws, IEnumerable<OfficeVisitsByTeacher> Teachers)
        {

            ws.Column(1).Width = 17.86;
            ws.Column(2).Width = 12.43;

            //Set Header titles
            ws.Cells[4, 1].Value = "Teachers";
            ws.Cells[4, 1].Style.Font.Bold = true;
            ws.Cells[5, 1].Value = "Teacher Name";
            ws.Cells[5, 1].Style.Border.BorderAround(ExcelBorderStyle.Thin);
           // ws.Cells[5, 1].AutoFilter = true;
            ws.Cells[5, 2].Value = "Office Visits";
            ws.Cells[5, 2].Style.Border.BorderAround(ExcelBorderStyle.Thin);
           // ws.Cells[5, 2].AutoFilter = true;

            //Get Data for Teachers       
            for (int i = 0; i < Teachers.Count(); i++)
            {
                ws.Cells[i + 6, 1].Value = Teachers.ElementAt(i).sent_by_contact_name;
                ws.Cells[i + 6, 1].Style.Border.BorderAround(ExcelBorderStyle.Thin);
                ws.Cells[i + 6, 2].Value = Teachers.ElementAt(i).total_visits;
                ws.Cells[i + 6, 2].Style.Border.BorderAround(ExcelBorderStyle.Thin);
            }

            //Set Header style
            using (ExcelRange rng = ws.Cells[4, 1, 5 + Teachers.Count(), 2])
            {
                rng.Style.Border.BorderAround(ExcelBorderStyle.Medium);            
            }

        }
开发者ID:heptadassembly,项目名称:SAMsUNFWebApplication,代码行数:37,代码来源:DashboardExcelExport.cs

示例14: GetJsonForCards

        internal static object GetJsonForCards(IEnumerable<Card> cards, int page)
        {
            if (cards == null)
            {
                return string.Empty;
            }

            var result = new
            {
                total = cards.Count(),
                page,
                records = cards.Count(),
                rows = cards.Select(x => new
                {
                    id = x.Id,
                    cell = new[]
                    {
                            x.CardNumber,
                            x.CardType.Name,
                            x.ExpirationDate.ToString("dd.MM.yyyy"),
                            x.Currency.Abbreveature,
                            Math.Round(x.Balance, 3).ToString()
                    }
                })

            };

            return result;
        }
开发者ID:hackersdelight,项目名称:BVP-banking,代码行数:29,代码来源:JSonConverters.cs

示例15: CreateInlineDiffs

        private void CreateInlineDiffs(IEnumerable<ILine> originals, IEnumerable<ILine> modifieds)
        {
            if (originals.Count() != modifieds.Count())
            {
                originalLines.AddRange(
                    originals.Select(x => new ModificationLine(new[] { new Span(x.Value, SpanKind.Deletion) }))
                );
                modifiedLines.AddRange(
                    modifieds.Select(x => new ModificationLine(new[] { new Span(x.Value, SpanKind.Addition) }))
                );
                return;
            }

            var maxLines = Math.Max(originals.Count(), modifieds.Count());

            for (var i = 0; i < maxLines; i++)
            {
                var originalLine = originals.ElementAtOrDefault(i);
                var modifiedLine = modifieds.ElementAtOrDefault(i);

                if (originalLine == null && modifiedLine == null)
                    continue;
                if (originalLine != null && modifiedLine == null)
                    originalLines.Add(new ModificationLine(new[] { new Span(originalLine.Value, SpanKind.Deletion) }));
                else if (originalLine == null)
                    modifiedLines.Add(new ModificationLine(new[] { new Span(modifiedLine.Value, SpanKind.Addition) }));
                else
                {
                    var originalToModifiedChanges = DiffInline(originalLine, modifiedLine);

                    originalLines.Add(new ModificationLine(new[] { new Span(originalLine.Value, SpanKind.Equal) }));
                    modifiedLines.Add(new ModificationLine(originalToModifiedChanges));
                }
            }
        }
开发者ID:jagregory,项目名称:sharpdiff,代码行数:35,代码来源:ModificationSnippet.cs


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