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


C# Dictionary.GetEnumerator方法代码示例

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


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

示例1: spinSmallText

        /// <summary>
        /// Get Spinned Sentences
        /// </summary>
        /// <param name="RawText">Format: (I/we/us) (am/are) planning to go (market/outing)...</param>
        /// <param name="RawText">Format: "|" or "/"...</param>
        /// <returns></returns>
        public static List<string> spinSmallText(string RawText, char separator)
        {
            #region Using Dictionary
            /// <summary>
            /// Hashtable that stores (DataInsideBraces) as Key and DataInsideBracesArray as Value
            /// </summary>
            //Hashtable commentsHashTable = new Hashtable();
            Dictionary<Match, string[]> commentsHashTable = new Dictionary<Match, string[]>();

            ///This is final possible cominations of comments
            List<string> listModComments = new List<string>();

            ///Put braces data in list of string array
            List<string[]> listDataInsideBracesArray = new List<string[]>();

            ///This Regex will fetch data within braces and put it in list of string array
            var regex = new Regex(@"\(([^)]*)\)", RegexOptions.Compiled);
            foreach (Match Data in regex.Matches(RawText))
            {
                string data = Data.Value.Replace("(", "").Replace(")", "");
                string[] DataInsideBracesArray = data.Split(separator);//data.Split('/');
                commentsHashTable.Add(Data, DataInsideBracesArray);
                listDataInsideBracesArray.Add(DataInsideBracesArray);
            }

            string ModifiedComment = RawText;

            IDictionaryEnumerator en = commentsHashTable.GetEnumerator();

            List<string> listModifiedComment = new List<string>();

            listModifiedComment.Add(ModifiedComment);

            //en.Reset();

            string ModifiedComment1 = ModifiedComment;

            #region Assigning Values and adding in List
            foreach (string[] item in listDataInsideBracesArray)
            {
                en.MoveNext();
                foreach (string modItem in listModifiedComment)
                {
                    foreach (string innerItem in item)
                    {
                        string ModComment = modItem.Replace(en.Key.ToString(), innerItem);
                        listModComments.Add(ModComment);
                    }
                }
                listModifiedComment.AddRange(listModComments);
                //string ModComment = ModifiedComment1.Replace(en.Key, item
            }
            #endregion

            List<string> listRequiredComments = listModifiedComment.FindAll(s => !s.Contains("("));

            //listComments.AddRange(listRequiredComments);
            return listRequiredComments;
            #endregion
        }
开发者ID:brentscheidt,项目名称:inboard,代码行数:66,代码来源:GlobusSpinHelper.cs

示例2: DumpElements

        public void DumpElements()
        {
            #if DEBUG
            Dictionary<IntPtr, int> list = new Dictionary<IntPtr,int>();

            IDictionaryEnumerator en = Elements.GetEnumerator();

            while (en.MoveNext())
            {
                if (!list.ContainsKey((IntPtr)en.Key))
                    {
                    list.Add((IntPtr)en.Key, 1);
                } else {
                    list[(IntPtr)en.Key] ++;
                }
            }
            en = list.GetEnumerator();

            long memused = 0;

            memused = GC.GetTotalMemory(true);

            Console.WriteLine("Begin dump of the Elements:\n");
            while (en.MoveNext())
            {
                Console.WriteLine("\t"+en.Key+"\tdup\t"+en.Value+"\ttype:\t"+Elements[(IntPtr)en.Key].ToString());
            }
            Console.WriteLine("=========================================================");
            Console.WriteLine("\tTotal memory used: "+memused+" Kb");
            #endif // Debug
        }
开发者ID:Paulus,项目名称:irrlichtnetcp,代码行数:31,代码来源:NativeElement.cs

示例3: GetEnumerator

        public IDictionaryEnumerator GetEnumerator()
        {

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

            foreach (XmlNode item in this.Document.GetElementsByTagName("add"))
            {

                set.Add(item.Attributes["name"].Value, item.Attributes["value"].Value);

            }

            return set.GetEnumerator();

        }
开发者ID:Ravivishnubhotla,项目名称:basewebframework,代码行数:15,代码来源:XmlResourceReader.cs

示例4: WriteMountCollection

        public virtual void WriteMountCollection( Dictionary<Serial, BaseCreature> dictionary, GenericWriter writer )
        {
            IDictionaryEnumerator myEnum = dictionary.GetEnumerator();

            int count = dictionary.Count;

            writer.Write( count );
            while( myEnum.MoveNext() )
            {
                Serial serial = ( Serial )myEnum.Key;
                Mobile m = (Mobile)myEnum.Value;

                writer.Write( serial );
                writer.Write( m );
            }
        }
开发者ID:FreeReign,项目名称:imaginenation,代码行数:16,代码来源:BasePvpStone.cs

示例5: MergesMetadata

            public void MergesMetadata()
            {
                // Given
                IExecutionContext context = Substitute.For<IExecutionContext>();
                context
                    .GetDocument(Arg.Any<IDocument>(), Arg.Any<string>(), Arg.Any<IEnumerable<KeyValuePair<string, object>>>())
                    .Returns(x =>
                    {
                        Dictionary<string, object> metadata = new Dictionary<string, object>();
                        foreach (KeyValuePair<string, object> kvp in x.ArgAt<IDocument>(0))
                        {
                            metadata[kvp.Key] = kvp.Value;
                        }
                        foreach (KeyValuePair<string, object> kvp in x.ArgAt<IEnumerable<KeyValuePair<string, object>>>(2))
                        {
                            metadata[kvp.Key] = kvp.Value;
                        }
                        IDocument result = Substitute.For<IDocument>();
                        result.GetEnumerator().Returns(metadata.GetEnumerator());
                        return result;
                    });
                IDocument a = Substitute.For<IDocument>();
                a.GetEnumerator().Returns(new Dictionary<string, object>
                {
                    { "a", 1 },
                    { "b", 2 }
                }.GetEnumerator());
                IDocument b = Substitute.For<IDocument>();
                b.GetEnumerator().Returns(new Dictionary<string, object>
                {
                    { "b", 3 },
                    { "c", 4 }
                }.GetEnumerator());
                Combine combine = new Combine();

                // When
                List<IDocument> results = combine.Execute(new[] { a, b }, context).ToList();  // Make sure to materialize the result list

                // Then
                CollectionAssert.AreEquivalent(new Dictionary<string, object>
                {
                    { "a", 1 },
                    { "b", 3 },
                    { "c", 4 }
                }, Iterate(results.First().GetEnumerator()));
            }
开发者ID:ibebbs,项目名称:Wyam,代码行数:46,代码来源:CombineTests.cs

示例6: Write

        private void Write(string fp, Dictionary<XmlTrack, List<string>> dic)
        {
            if (dic.Count > 0)
            {
                using (StreamWriter sw = new StreamWriter(fp, false))
                {
                    IEnumerator i = dic.GetEnumerator();
                    KeyValuePair<XmlTrack, List<string>> kvp = new KeyValuePair<XmlTrack, List<string>>();

                    while (i.MoveNext())
                    {
                        kvp = (KeyValuePair<XmlTrack, List<string>>)i.Current;
                        XmlTrack track = kvp.Key;
                        List<string> missingTags = kvp.Value;
                        string errors = string.Join("; ", missingTags.ToArray());
                        sw.WriteLine(track.Location + " --> " + errors);
                    }
                }
            }
        }
开发者ID:OriginalCliff,项目名称:itsfv,代码行数:20,代码来源:ReportWriter.cs

示例7: Encode

        public static string Encode(Dictionary<string, string> dictionary )
        {
            var @value = "";
            var e = dictionary.GetEnumerator();
            bool hasFirst = e.MoveNext();
            if (hasFirst)
            {
                var tb = new StringBuilder();
// ReSharper disable PossibleNullReferenceException
                tb.Append(e.Current.Key).Append("=").Append(e.Current.Value);
// ReSharper restore PossibleNullReferenceException
                while (e.MoveNext())
                {
// ReSharper disable PossibleNullReferenceException
                    tb.Append("; ").Append(e.Current.Key).Append("=").Append(e.Current.Value);
// ReSharper restore PossibleNullReferenceException
                }
                @value = tb.ToString();
            }
            return @value;
        }
开发者ID:gitter-badger,项目名称:vc-community-1.x,代码行数:21,代码来源:PairsParser.cs

示例8: ValueEnumerator_Current

		// based on #491858, #517415
		public void ValueEnumerator_Current ()
		{
			var e1 = new Dictionary<int,int>.ValueCollection.Enumerator ();
			Assert.IsFalse (Throws (delegate { var x = e1.Current; }));

			var d = new Dictionary<int,int> ().Values;
			var e2 = d.GetEnumerator ();
			Assert.IsFalse (Throws (delegate { var x = e2.Current; }));
			e2.MoveNext ();
			Assert.IsFalse (Throws (delegate { var x = e2.Current; }));
			e2.Dispose ();
			Assert.IsFalse (Throws (delegate { var x = e2.Current; }));

			var e3 = ((IEnumerable<int>) d).GetEnumerator ();
			Assert.IsFalse (Throws (delegate { var x = e3.Current; }));
			e3.MoveNext ();
			Assert.IsFalse (Throws (delegate { var x = e3.Current; }));
			e3.Dispose ();
			Assert.IsFalse (Throws (delegate { var x = e3.Current; }));

			var e4 = ((IEnumerable) d).GetEnumerator ();
			Assert.IsTrue (Throws (delegate { var x = e4.Current; }));
			e4.MoveNext ();
			Assert.IsTrue (Throws (delegate { var x = e4.Current; }));
			((IDisposable) e4).Dispose ();
			Assert.IsTrue (Throws (delegate { var x = e4.Current; }));
		}
开发者ID:t-ashula,项目名称:mono,代码行数:28,代码来源:DictionaryTest.cs

示例9: Dictionary_MoveNext

		[Test] // bug #332534
		public void Dictionary_MoveNext ()
		{
			Dictionary<int,int> a = new Dictionary<int,int>();
			a.Add(3,1);
			a.Add(4,1);

			IEnumerator en = a.GetEnumerator();
			for (int i = 1; i < 10; i++)
				en.MoveNext();
		}
开发者ID:t-ashula,项目名称:mono,代码行数:11,代码来源:DictionaryTest.cs

示例10: generateOrderTable

        private String generateOrderTable(Dictionary<String, Double> config)
        {
            String tableStr = "";
            int nextId = 1;
            IDictionaryEnumerator ienum = config.GetEnumerator();
            while (ienum.MoveNext())
            {
                String key = (String)ienum.Key;
                Double val = (Double)ienum.Value;

                if (tableStr.Length > 0)
                {
                    tableStr += ", ";
                    tableStr += Environment.NewLine;
                }
                else
                {
                    tableStr += "{";
                    tableStr += Environment.NewLine;
                }

                tableStr += "[";
                if (key.GetType() == typeof(Double))
                {
                    tableStr += key;
                }
                else
                {
                    tableStr += "\"" + key + "\"";
                }
                tableStr += "] = ";

                if (val > 0.0)
                {
                    //append next id
                    tableStr += nextId;
                }
                else
                {
                    //its disabled just append 0
                    tableStr += "0";
                }

                nextId++;
            }


            if (tableStr.Length > 0)
            {
                tableStr += Environment.NewLine;
                tableStr += "}";
            }

            return tableStr;
        }
开发者ID:GoogleFrog,项目名称:Zero-K-Infrastructure,代码行数:55,代码来源:SimpleLuaParser.cs

示例11: Execute

        /// <summary>
        /// Execute the MSBuild Task.
        /// </summary>
        /// <returns></returns>
        public override bool Execute()
        {
            _modifiedFiles = new ArrayList();
            _deletedFiles = new ArrayList();

            // Parse local manifest to retrieve list of files and their hashes.
            string[] localManifest = File.ReadAllLines(_localManifestFile);
            Dictionary<string, string> localFiles = new Dictionary<string,string>();
            for (int i = 0; i < localManifest.Length; i++)
            {
                if (localManifest[i].StartsWith("Archive-Asset-Name: "))
                {
                    string assetName = localManifest[i].Substring(20);
                    i++;
                    if (localManifest[i].StartsWith("Archive-Asset-SHA-512-Digest: "))
                    {
                        string assetHash = localManifest[i].Substring(30);
                        localFiles.Add(assetName, assetHash);
                    }
                    else
                    {
                        return false;
                    }
                }
            }

            // Do the same for the target manifest.
            string[] targetManifest = File.ReadAllLines(_targetManifestFile);
            Dictionary<string, string> targetFiles = new Dictionary<string,string>();
            for (int i = 0; i < targetManifest.Length; i++)
            {
                if (targetManifest[i].StartsWith("Archive-Asset-Name: "))
                {
                    string assetName = targetManifest[i].Substring(20);
                    i++;
                    if (targetManifest[i].StartsWith("Archive-Asset-SHA-512-Digest: "))
                    {
                        string assetHash = targetManifest[i].Substring(30);
                        targetFiles.Add(assetName, assetHash);
                    }
                    else
                    {
                        return false;
                    }
                }
            }

            // Compare hashes and populate the lists of modified and deleted files.
            string[] targetFileMap = File.ReadAllLines(_targetFileMap);
            foreach (KeyValuePair<string, string> file in localFiles)
            {
                // For some reason this MANIFEST.bbr file appears in the manifest, even though
                // it doesn't actually exist anywhere...?  It doesn't seem to correspond to
                // MANIFEST.MF either.
                if (file.Key == "META-INF/MANIFEST.bbr")
                {
                    continue;
                }

                // If the target manifest doesn't contain the same key/value pair,
                // that means the local file has been either added or modified.
                if (!targetFiles.Contains(file))
                {
                    TaskItem item = new TaskItem(file.Key);
                    item.SetMetadata("SourcePath", getSourcePath(file.Key, targetFileMap));
                    _modifiedFiles.Add(item);
                }
            }

            IDictionaryEnumerator targetEnum = targetFiles.GetEnumerator();
            while (targetEnum.MoveNext())
            {
                // If the local manifest doesn't contain the same key,
                // that means the target file has been deleted from the project.
                if (!localFiles.ContainsKey((string)targetEnum.Key))
                {
                    TaskItem item = new TaskItem((string)targetEnum.Key);
                    _deletedFiles.Add(item);
                }
            }

            // For some reason the manifest file doesn't show up in the target file map
            // or the manifest itself, so we add it manually here and always upload it.
            TaskItem manifestItem = new TaskItem("META-INF/MANIFEST.MF");
            manifestItem.SetMetadata("SourcePath", "localManifest.mf");
            _modifiedFiles.Add(manifestItem);

            return true;
        }
开发者ID:blackberry,项目名称:VSPlugin,代码行数:93,代码来源:DiffManifests.cs

示例12: WriteResults

 private void WriteResults(bool csvOutput, Dictionary<String, String> pdfInfo)
 {
     if (pdfInfo.Count > 0)
     {
         IDictionaryEnumerator infoEnumerator = pdfInfo.GetEnumerator();
         while (infoEnumerator.MoveNext())
         {
             switch (csvOutput)
             {
                 case (true):
                     System.Console.WriteLine(String.Format(reportMessageCSVOutput, infoEnumerator.Key, infoEnumerator.Value));
                     break;
                 default:
                     System.Console.WriteLine(String.Format(reportMessageStandardOutput, infoEnumerator.Key, infoEnumerator.Value));
                     break;
             }
         }
     }
     else
     {
         System.Console.WriteLine(Environment.NewLine + reportNoPdfInfo);
     }
 }
开发者ID:stchan,项目名称:PdfMiniTools,代码行数:23,代码来源:TaskProcessor.cs

示例13: BuildCraftedItem

		/// <summary>
		/// Make the crafted item and add it to player's inventory
		/// </summary>
		/// <param name="player"></param>
		/// <param name="recipe"></param>
		/// <returns></returns>
		protected virtual void BuildCraftedItem(GamePlayer player, DBCraftedItem recipe, ItemTemplate itemToCraft)
		{
			Dictionary<int, int> changedSlots = new Dictionary<int, int>(5); // key : > 0 inventory ; < 0 ground || value: < 0 = new item count; > 0 = add to old

			lock (player.Inventory)
			{
				int count = itemToCraft.PackSize < 1 ? 1 : itemToCraft.PackSize;
				foreach (InventoryItem item in player.Inventory.GetItemRange(eInventorySlot.FirstBackpack, eInventorySlot.LastBackpack))
				{
					if (item == null)
						continue;

					if (item.Id_nb.Equals(itemToCraft.Id_nb) == false)
						continue;

					if (item.Count >= itemToCraft.MaxCount)
						continue;

					int countFree = item.MaxCount - item.Count;
					if (count > countFree)
					{
						changedSlots.Add(item.SlotPosition, countFree); // existing item should be changed
						count -= countFree;
					}
					else
					{
						changedSlots.Add(item.SlotPosition, count); // existing item should be changed
						count = 0;
						break;
					}
				}

				if (count > 0) // Add new object
				{
					eInventorySlot firstEmptySlot = player.Inventory.FindFirstEmptySlot(eInventorySlot.FirstBackpack, eInventorySlot.LastBackpack);
					if (firstEmptySlot == eInventorySlot.Invalid)
					{
						changedSlots.Add(-1, -count); // Create the item on the ground
					}
					else
					{
						changedSlots.Add((int)firstEmptySlot, -count); // Create the item in the free slot
					}
					count = 0;
				}

				InventoryItem newItem = null;

				player.Inventory.BeginChanges();

				Dictionary<int, int>.Enumerator enumerator = changedSlots.GetEnumerator();
				while (enumerator.MoveNext())
				{
					KeyValuePair<int, int> slot = enumerator.Current;
					int countToAdd = slot.Value;
					if (countToAdd > 0)	// Add to exiting item
					{
						newItem = player.Inventory.GetItem((eInventorySlot)slot.Key);
						if (newItem != null && player.Inventory.AddCountToStack(newItem, countToAdd))
						{
							InventoryLogging.LogInventoryAction("(craft)", player, eInventoryActionType.Other, newItem.Template, countToAdd);
							// count incremented, continue with next change
							continue;
						}
					}

					if (recipe.MakeTemplated)
					{
						string adjItem = itemToCraft.Id_nb+(GetQuality(player, recipe).ToString());
						ItemTemplate adjItemToCraft = GameServer.Database.FindObjectByKey<ItemTemplate>(adjItem);
						if (adjItemToCraft != null)
						{
							newItem = GameInventoryItem.Create<ItemTemplate>(adjItemToCraft);
						}
						else
						{
							newItem = GameInventoryItem.Create<ItemTemplate>(itemToCraft);
						}
					}
					else
					{
						ItemUnique unique = new ItemUnique(itemToCraft);
						GameServer.Database.AddObject(unique);
						newItem = GameInventoryItem.Create<ItemUnique>(unique);
						newItem.Quality = GetQuality(player, recipe);
					}

					newItem.IsCrafted = true;
					newItem.Creator = player.Name;
					newItem.Count = -countToAdd;

					if (slot.Key > 0)	// Create new item in the backpack
					{
						player.Inventory.AddItem((eInventorySlot)slot.Key, newItem);
//.........这里部分代码省略.........
开发者ID:Refizul,项目名称:DOL-Kheldron,代码行数:101,代码来源:AbstractCraftingSkill.cs

示例14: SerializeDictInt

        private static bool SerializeDictInt(Dictionary<string, int> dictionary, StringBuilder builder)
        {
            builder.Append("{");

            IDictionaryEnumerator e = dictionary.GetEnumerator();
            bool first = true;
            while (e.MoveNext())
            {
                string key = e.Key.ToString();
                object value = e.Value;

                if (!first)
                {
                    builder.Append(", ");
                }

                SerializeString(key, builder);
                builder.Append(":");
                if (!SerializeValue(value, builder))
                {
                    return false;
                }

                first = false;
            }

            builder.Append("}");
            return true;
        }
开发者ID:ricardochaves,项目名称:MasterControl,代码行数:29,代码来源:JSON.cs

示例15: Page_Load

        protected void Page_Load(object sender, EventArgs e)
        {
            if (Session["UserID"] == null)
                Response.Redirect("../login.aspx");

            if (!IsPostBack)
            {
                // build table of service admin grants
                servAdminGrants = getServiceAdminGrants();
                if (servAdminGrants != null)
                {
                    // load the PA's that this user is an administer of
                    Dictionary<int, List<Grant>>.Enumerator paEnum = servAdminGrants.GetEnumerator();
                    paDropDownList.Items.Add(new ListItem("--- Select Process Agent ---"));

                    while (paEnum.MoveNext())
                    {
                        KeyValuePair<int, List<Grant>> entry = paEnum.Current;
                        IntTag tag = ticketIssuer.GetProcessAgentTagWithType((int)entry.Key);
                        if (tag != null)
                        {
                            string agentName = tag.tag;
                            List<Grant> grants = entry.Value;
                            StringBuilder buf = new StringBuilder();
                            int count = 0;
                            foreach (Grant g in grants)
                            {
                                if (count > 0)
                                {
                                    buf.Append(",");
                                }
                                buf.Append(g.grantID);
                                count++;
                            }
                            paDropDownList.Items.Add(new ListItem(agentName, buf.ToString()));
                        }
                    }
                }

            }
        }
开发者ID:gumpyoung,项目名称:ilabproject-code,代码行数:41,代码来源:adminServices.aspx.cs


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