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


C# Dictionary.Count方法代码示例

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


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

示例1: Bully

    /***
     * Bully class constructor   */
    public Bully(Dictionary<int, String> candidateMachines)
    {
        machines = candidateMachines;
        n = candidateMachines.Count();
        positionValue = new int[candidateMachines.Count()];
        for (int i = 0; i < candidateMachines.Count(); i++)
        {
            positionValue[i] = candidateMachines.Keys.ElementAt(i);
        }

        Console.WriteLine(classNameLog + "New instance of bully generator with machines " + machines);
        Console.WriteLine(classNameLog + "Key values array" + positionValue);
        myIp = CSharpRpcServer.getMyIpAddress();
    }
开发者ID:UkiMiawz,项目名称:data-communication,代码行数:16,代码来源:Bully.cs

示例2: getFrameVisitFromLevel

 public void getFrameVisitFromLevel(List<Visit> listVisit, out HelperFrame.GroupType groupType, out Dictionary<string, List<Visit>> visitByDate)
 {
     this.visits = listVisit;
     groupType = HelperFrame.GroupType.DAY;
     visitByDate = HelperDate.getVisitsByDate(listVisit, "dd MMM");
     if (!isBlend(visitByDate.Count()))
     {
         groupType = HelperFrame.GroupType.WEEK;
         visitByDate = HelperDate.getVisitsByWeek(listVisit);
         if (!isBlend(visitByDate.Count()))
         {
             groupType = HelperFrame.GroupType.MONTH;
             visitByDate = HelperDate.getVisitsByDate(listVisit, "MMM yyyy");
         }
     }
 }
开发者ID:Karnlie,项目名称:almazovdata,代码行数:16,代码来源:BottomFrame.cs

示例3: AddQueryString

    public static string AddQueryString( string url, string key, string value)
    {
        string result = url;
            string[] t = url.Split('?');
            string path = t[0];
            string[] querystring = new string[]{};

            if(t.Length > 1)
                querystring = t[1].Split('&');

            Dictionary<string, string> queryParams = new Dictionary<string,string>();

            foreach( string q in querystring ){
                if( q != string.Empty )
                    queryParams.Add( q.Split('=')[0], q.Split('=')[1]);
            }

           if( queryParams.ContainsKey(key) )
               queryParams[key] = value;
           else
               queryParams.Add( key, value);

            result = path;
            if( queryParams.Count() > 0)
            {
                result += "?";
                foreach( string k in queryParams.Keys )
                    result += k + "=" + queryParams[k] + "&";
                if (result.EndsWith("&"))
                    result = result.TrimEnd('&');
            }

            return result;
    }
开发者ID:ojensen,项目名称:WhatsOnInstant,代码行数:34,代码来源:QueryString.cs

示例4: Register

 /// <summary>
 /// 用户向消息总线注册
 /// </summary>
 public void Register()
 {
     //向共享内存中写入数据,进行注册
     int pid = Process.GetCurrentProcess().Id;
     string address = ".\\Private$\\myQueue" + pid;
     MyLocker.Lock("sm");
     try
     {
         processDic = (Dictionary<int, string>)sm.Data;
     }
     catch (Exception ex)
     {
         processDic = new Dictionary<int, string>();
     }
     if (!processDic.ContainsKey(pid))
     {
         processDic.Add(pid, address);
         sm.Data = processDic;
     }
     processDic = (Dictionary<int, string>)sm.Data;
     localV = sm.Version;
     MyLocker.Unlock("sm");
     Console.WriteLine("客户端数量:" + processDic.Count());
     ReceiveNow();
 }
开发者ID:unclechao,项目名称:Message-Manage,代码行数:28,代码来源:MessageManage.cs

示例5: RetrieveBox

        private GeoBoundingBoxFilter RetrieveBox(string fieldName, Dictionary<string, object> boxDict)
        {
            // maybe are are dealing with the vertices
            if (boxDict.Count() == 4)
                return GetBoxFromVertices(fieldName, boxDict);

            CoordinatePoint topLeft;
            CoordinatePoint bottomRight;
            if (boxDict.ContainsKey(_TOP_LEFT))
            {
                topLeft = CoordinatePointSerializer.DeserializeCoordinatePoint(boxDict.GetString(_TOP_LEFT));
                bottomRight = CoordinatePointSerializer.DeserializeCoordinatePoint(boxDict.GetString(_BOTTOM_RIGHT));
            }
            else if (boxDict.ContainsKey(_TOP_RIGHT))
            {
                CoordinatePoint topRight = CoordinatePointSerializer.DeserializeCoordinatePoint(boxDict.GetString(_TOP_RIGHT));
                CoordinatePoint bottomLeft = CoordinatePointSerializer.DeserializeCoordinatePoint(boxDict.GetString(_BOTTOM_LEFT));

                topLeft = new CoordinatePoint(topRight.Latitude, bottomLeft.Longitude);
                bottomRight = new CoordinatePoint(bottomLeft.Latitude, topRight.Longitude);
            }
            else
            {
                throw new Exception("No bounding box formed by current properties.");
            }

            return new GeoBoundingBoxFilter(fieldName, topLeft, bottomRight);
        }
开发者ID:kbolay,项目名称:Bolay.Elastic,代码行数:28,代码来源:GeoBoundingBoxSerializer.cs

示例6: ProblemA

        private static void ProblemA()
        {
            var addressCount = int.Parse(Console.ReadLine());

            var addresses = new Dictionary<string, List<string>>();

            for (int i = 0; i < addressCount; i++)
            {
                var email = Console.ReadLine();
                var canonicalEmail = GetCanonicalEmail(email);

                if (addresses.ContainsKey(canonicalEmail))
                    addresses[canonicalEmail].Add(email);
                else
                    addresses.Add(canonicalEmail, new List<string> { email });
            }

            Console.WriteLine(addresses.Count());

            foreach (var a in addresses)
            {
                Console.Write(a.Value.Count);
                Console.Write(' ');

                foreach (var item in a.Value)
                {
                    Console.Write(item + ' ');
                }
                Console.WriteLine();
            }
        }
开发者ID:kbalodis,项目名称:notes10,代码行数:31,代码来源:Program.cs

示例7: HeaderInfo

        private void HeaderInfo()
        {
            this.Output.AppendLine(Messages.WavesSeparator);
            if (this.IsLogged)
            {
                this.Output.AppendLine(string.Format(Messages.UserWelcomeMessage,
                    this.CurrentUser.Username));
            }
            else
            {
                this.Output.AppendLine(string.Format(Messages.GuestWelcomeMessage));
            }

            var allQuestions = this.Questions;
            var hotQuestions = allQuestions.Sum(question => question.Answers.OfType<BestAnswer>().Count());

            var allAnswers = this.Answers;
            var userAnswers = new Dictionary<string, int>();
            foreach (var answer in allAnswers)
            {
                var author = answer.Author.Username;
                if (!userAnswers.ContainsKey(author))
                {
                    userAnswers.Add(author, 0);
                }

                userAnswers[author]++;
            }

            var activeUsers = userAnswers.Count(user => user.Value >= 3);

            this.Output.AppendLine(string.Format(Messages.GeneralHeaderMessage,
                    hotQuestions, activeUsers));
            this.Output.AppendLine(Messages.WavesSeparator);
        }
开发者ID:peterkirilov,项目名称:SoftUni-1,代码行数:35,代码来源:ExtendedForum.cs

示例8: GestionCarte

        /// <summary>
        /// Constructeur paramétré
        /// </summary>
        /// <param name="journees">Liste des journées de la mission</param>
        public GestionCarte(Dictionary<int, Journee> journees)
        {
            InitializeComponent();

            this.journees = journees;

            lieuxADessiner = new List<Lieu>();

            TreeNode t = new TreeNode("Tout afficher");

            activitesExterieures.Nodes.Add(t);
            activitesExterieures.SelectedNode = t;

            for (int i = 1; i <= journees.Count(); ++i)
            {
                if (journees[i].isJourneeExterieure())
                {
                    TreeNode tn = new TreeNode("Journée " + i);
                    activitesExterieures.Nodes.Add(tn);

                    foreach (Activite a in journees[i].getActivites())
                        if (a.isActiviteExterieure())
                        {
                            TreeNode tnn = new TreeNode(a.getNom() + " - " + a.getHeureDebut().getHeures() + "h -> " + a.getHeureFin().getHeures() + "h");
                            tnn.Tag = a;
                            tn.Nodes.Add(tnn);

                            lieuxADessiner.Add(a.getLieu());
                        }
                }
            }

            this.Refresh();
        }
开发者ID:Nalhyyk,项目名称:MarsCalendar,代码行数:38,代码来源:GestionCarte.cs

示例9: CharHistogram

        private static void CharHistogram(string str)
        {
            Dictionary<char,int> dict=new Dictionary<char,int>();
            foreach (var item in str)
            {
                if (dict.ContainsKey(item))
                {
                    dict[item] += 1;
                }
                else
                {
                    dict.Add(item, 1);
                }
            }

            int counter = 0;
            Console.Write("{ ");
            foreach (var ch in dict)
            {
                if (counter==dict.Count()-1)
                {
                    Console.Write("'" + ch.Key + "'" + ": " + ch.Value + " }");
                }
                else
                {
                    Console.Write("'" + ch.Key + "'" + ": " + ch.Value + ", ");
                }
                counter++;
            }
        }
开发者ID:Redsart,项目名称:HackBulgaria,代码行数:30,代码来源:CharHistograms.cs

示例10: Test_Analyze

        public void Test_Analyze()
        {
            var httpClientMock = new Mock<IHttpClient>();
            httpClientMock.Setup(it => it.DownloadString(It.IsAny<string>()))
                .Returns<string>((url) =>
                {
                    return "script";
                });

            var siteFileProviderMock = new Mock<ISiteFileProvider>();
            Dictionary<string, string> styles = new Dictionary<string, string>();
            siteFileProviderMock.Setup(it => it.AddFile(It.IsAny<Site>(), It.IsAny<string>(), It.IsAny<string>()))
                .Callback<Site, string, string>((site1, path, content) =>
                {
                    styles.Add(path, content);
                });

            var scriptAnalyzer = new ScriptAnalyzer(httpClientMock.Object, siteFileProviderMock.Object);

            var pageHtml = @"<html>
            <head>
            <script src=""/script1.js"" type=""text/javascript""></script>
<script src=""/script2.js"" type=""text/javascript""></script>
</head>
            <body>
            </body>
            </html>";

            SiteDownloadContext siteDownloadContext = new SiteDownloadContext(null, new DownloadOptions() { SiteName = "Test_Analyze", Url = "localhost", Pages = 20, Deep = 1 }, null, null);
            PageDownloadContext pageDownloadContext = new PageDownloadContext(siteDownloadContext, new PageLevel("http://localhost", 1), pageHtml);

            scriptAnalyzer.Analyze(pageDownloadContext);

            Assert.AreEqual(2, styles.Count());
            Assert.AreEqual("script", styles["\\Scripts\\script1.js"]);
开发者ID:Kooboo,项目名称:Ovaldi,代码行数:35,代码来源:ScriptAnalyzerTests.cs

示例11: AggregatesDataIntoDictionary

            public void AggregatesDataIntoDictionary()
            {
                var lastReductionTime = new DateTime(2011, 11, 11, 5, 30, 0, 0);
                var reduceLevel = new ReduceLevel { Resolution = 5000 };
                var sourceAggregationList = new List<MonitorRecord<double>>
                                                {
                                                    new MonitorRecord<double>(new DateTime(2011, 11, 11, 5, 30, 0, 500), 5, 5),
                                                    new MonitorRecord<double>(new DateTime(2011, 11, 11, 5, 30, 1, 0), 25, 4),
                                                    new MonitorRecord<double>(new DateTime(2011, 11, 11, 5, 30, 1, 500), 7, 8),
                                                    new MonitorRecord<double>(new DateTime(2011, 11, 11, 5, 30, 40, 0), 3, 3)
                                                };
                var destination = new Dictionary<DateTime, IList<MonitorRecord<double>>>();

                var aggregater = new RecordReduceAggregate();
                var result = aggregater.Aggregate(lastReductionTime, reduceLevel, sourceAggregationList, destination);

                Assert.Equal(2, destination.Count());

                var firstItem = destination.First();
                Assert.Equal(new DateTime(2011, 11, 11, 5, 30, 2, 500), firstItem.Key);
                Assert.Equal(3, firstItem.Value.Count);

                var lastItem = destination.Last();
                Assert.Equal(new DateTime(2011, 11, 11, 5, 30, 42, 500), lastItem.Key);
                Assert.Equal(1, lastItem.Value.Count);
            }
开发者ID:srinchiera,项目名称:ZocMon,代码行数:26,代码来源:TestForRecordReduceAggregate.cs

示例12: BruteForce

        private static int BruteForce()
        {
            //read Pythagorean Triplets on wikipedia

            var map = new Dictionary<int, int>();
            var sqrt = Math.Sqrt(750000);

            for (var m = 2; m < sqrt; m++)
            {
                for (var n = 1; n < m; n++)
                {
                    if ((m + n)%2 > 0 && MathUtils.Gcd(m, n) == 1)
                    {
                        var a = m*m - n*n;
                        var b = 2*m*n;
                        var c = m*m + n*n;

                        var d = a + b + c;
                        while (d <= 1500000)
                        {
                            if (!map.ContainsKey(d))
                            {
                                map.Add(d, 0);
                            }
                            map[d]++;
                            d += a + b + c;
                        }
                    }
                }
            }

            return map.Count(x => x.Value == 1);
        }
开发者ID:david--liu,项目名称:code_kata,代码行数:33,代码来源:Problem75.cs

示例13: Filler

        //constructors;
        public Filler(DMSImage Source)
            : base(new Size(Source.Width, Source.Height), Source, Color.Gray)
        {
            m_pixelindex = new Dictionary<int, int>();
            m_pixels = new List<PixelInfo>();
            m_resolution = START_RESOLUTION;
            m_rand = new Random();
            double delta = 0;
            int iter = 0;

            while (m_pixels.Count < MIN_PIXELS || delta > DELTA_THRESHOLD && iter < MAX_ITERS)
            {
                if (iter == MAX_ITERS || delta < DELTA_THRESHOLD)
                {
                    iter = 0;
                    m_resolution >>= 1;
                    if (m_resolution == 0) break;
                    Console.Write("\n" + m_resolution);

                    //bring on new pixels if necessary
                    for (int u = 0; u < Source.Width; u += m_resolution)
                    {
                        for (int v = 0; v < Source.Height; v += m_resolution)
                        {
                            if (GetPixelHelper(u, v) == null)
                            {
                                PixelInfo newpixel = new PixelInfo(u, v, new Point3D());
                                newpixel.SetNeighbors(m_Source, m_resolution);
                                SetAvgColour(newpixel);

                                m_pixels.Add(newpixel);
                                m_pixelindex.Add(v * Source.Width + u, m_pixels.Count() - 1);
                            }
                        }
                    }
                }
                else
                {
                    iter++;
                }

                Console.Write('.');

                //do the averaging!
                delta = 0.0;
                if (m_pixels.Count() == 0) continue;
                for (int i = 0; i < 10000; i++)
                {
                    int idx = m_rand.Next(m_pixelindex.Count());
                    idx = m_pixelindex.Keys.ToArray()[idx];
                    int u = idx % Source.Width;
                    int v = idx / Source.Width;
                    int pixelidx = m_pixelindex[idx];

                    delta += SetAvgColour(m_pixels[pixelidx]);
                }
            }
            Console.WriteLine();
        }
开发者ID:dmswart,项目名称:Personal-Projects,代码行数:60,代码来源:Filler.cs

示例14: isDrawActive

        public bool isDrawActive(UserInfo[] userInfos, Skeleton[] skeletons) 
        {
            Dictionary<int, double> userDistanceList = new Dictionary<int, double>();

            foreach (var userInfo in userInfos)
            {
                int userID = userInfo.SkeletonTrackingId;
                if (userID == 0)
                {
                    continue;
                }

                foreach (var skel in skeletons) 
                {
                    double skeletonPosition;
                    if (skel.TrackingId == userID)
                    {
                        skeletonPosition = skel.Position.Z;
                        userDistanceList[userID] = skeletonPosition;
                    }
                    else 
                    {
                        continue;
                    }
                }
            }
            if (userDistanceList.Count() == 0)
                return false;
            	        
		    // get id of the closest user
            double smallest = 100000.0;
            int UserIdOfClosest = 0;

            foreach (KeyValuePair<int, double> entry in userDistanceList)
            {
                if (entry.Value < smallest) {
                    smallest = entry.Value;
                    UserIdOfClosest = entry.Key;
                }
            }
            if (UserIdOfClosest == 0) 
            {
                return false;
            }
            	        
		     // check if the closest users action is triggered 
            foreach (var userInfo in userInfos){
                if (userInfo.SkeletonTrackingId == UserIdOfClosest)
                {
                    return modesList.ElementAt(currentModeId).isInteractionActive(userInfo.HandPointers);   
                }
                else
                {
                    continue;
                }
            }
            return false;  
        }
开发者ID:dolphinlcj,项目名称:motion-paint,代码行数:58,代码来源:ControlManager.cs

示例15: Mean

 internal static double Mean(Dictionary<DateTime, double> returns)
 {
     double S = 0;
     foreach(KeyValuePair<DateTime, double> kvp in returns)
     {
         S += kvp.Value;
     }
     return S/returns.Count();
 }
开发者ID:bonkoskk,项目名称:peps,代码行数:9,代码来源:ComputationTools.cs


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