當前位置: 首頁>>代碼示例>>C#>>正文


C# List.GroupBy方法代碼示例

本文整理匯總了C#中Service.List.GroupBy方法的典型用法代碼示例。如果您正苦於以下問題:C# List.GroupBy方法的具體用法?C# List.GroupBy怎麽用?C# List.GroupBy使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Service.List的用法示例。


在下文中一共展示了List.GroupBy方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: GetTime

        /// <summary>
        /// Gets the total time spended on TS3 for specified clients.
        /// </summary>
        /// <param name="clientDatabaseIds">The client database ids.</param>
        /// <param name="fromTime">From time.</param>
        /// <param name="toTime">To time.</param>
        /// <returns></returns>
        public Dictionary<uint, double> GetTime(IEnumerable<uint> clientDatabaseIds, DateTime? fromTime, DateTime? toTime)
        {
            lock (Container.lockTimeClientList)
            {
                lock (Repository.Container.lockDatabase)
                {
                    var times = new List<TimeClientEntity>();
                    using (var command = new SQLiteCommand(this.Container.DatabaseConnection))
                    {
                        command.CommandText = string.Format("SELECT ClientDatabaseId, Joined, Disconnected, TotalMinutes FROM Time WHERE ClientDatabaseId IN ({0})", string.Join(", ", clientDatabaseIds));
                        if (fromTime.HasValue) command.CommandText += string.Format(" AND Disconnected > {0}", fromTime.Value.ToTimeStamp());
                        if (toTime.HasValue) command.CommandText += string.Format(" AND Joined < {0}", toTime.Value.ToTimeStamp());

                        using (var reader = command.ExecuteReader())
                        {
                            while (reader.HasRows && reader.Read())
                            {
                                times.Add(new TimeClientEntity
                                {
                                    User = (uint)reader.GetInt32(0),
                                    Joined = reader.GetInt32(1).ToDateTime(),
                                    Disconnected = reader.GetInt32(2).ToDateTime(),
                                    TotalMinutes = reader.GetInt32(3)
                                });
                            }
                        }
                    }

                    return times.GroupBy(m => m.User).ToDictionary(g => (uint)g.Key, g => g.Sum(m => m.GetTime(fromTime, toTime)));
                }
            }
        }
開發者ID:Oslo-Lions-Elektroniske-Sportsklubb,項目名稱:TS3-Bot,代碼行數:39,代碼來源:ClientData.cs


注:本文中的Service.List.GroupBy方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。