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


C# HashMap.Add方法代码示例

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


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

示例1: Main

 static void Main(string[] args)
 {
     HashMap<int, int> test = new HashMap<int, int>();
     test.Add(1, 2);
     test.Add(2, 3);
     test.Add(3, 4);
     test.Add(4, 5);
     Console.WriteLine(test.Contains(22));
     foreach (var item in test)
     {
         Console.WriteLine($"{item.Key}    {item.Value}");
     }
 }
开发者ID:ivanov961,项目名称:HackBulgaria,代码行数:13,代码来源:Program.cs

示例2: Init1

 /// <summary>
 ///     person.dic
 /// </summary>
 private void Init1()
 {
     TextReader br = null;
     try
     {
         _personNatureAttrs = new HashMap<string, PersonNatureAttr>();
         br = MyStaticValue.GetPersonReader();
         string temp;
         while ((temp = br.ReadLine()) != null)
         {
             var strs = temp.Split('\t');
             var pna = _personNatureAttrs[strs[0]];
             if (pna == null)
             {
                 pna = new PersonNatureAttr();
             }
             pna.AddFreq(int.Parse(strs[1]), int.Parse(strs[2]));
             _personNatureAttrs.Add(strs[0], pna);
         }
     }
     finally
     {
         if (br != null)
             br.Close();
     }
 }
开发者ID:echofool,项目名称:Ansj.Net,代码行数:29,代码来源:PersonAttrLibrary.cs

示例3: Main

        public static void Main()
        {
            Console.WriteLine("Enter contacts (name - number) or search existing contacts (type 'search'):");
            HashMap<string, string> phonebook = new HashMap<string, string>();

            string entry = Console.ReadLine();

            while (entry != "search")
            {
                string[] contactInfo = entry
                    .Split(new char[] { '-' }, StringSplitOptions.RemoveEmptyEntries)
                    .Select(s => s.Trim())
                    .ToArray();
                if (!phonebook.ContainsKey(contactInfo[0]))
                {
                    phonebook.Add(contactInfo[0], contactInfo[1]);
                }

                entry = Console.ReadLine();
            }

            List<string> searchWords = new List<string>();
            string word = Console.ReadLine();
            while (word != string.Empty)
            {
                searchWords.Add(word);
                word = Console.ReadLine();
            }

            foreach (var searchWord in searchWords)
            {
                if (phonebook.ContainsKey(searchWord))
                {
                    Console.WriteLine("{0} -> {1}", searchWord, phonebook[searchWord]);
                }
                else
                {
                    Console.WriteLine("Contact {0} does not exist.", searchWord);
                }
            }
        }
开发者ID:straho99,项目名称:Data-Structures---homeworks,代码行数:41,代码来源:Phonebook.cs

示例4: Init

        // company_freq

        private static void Init()
        {
            // TODO Auto-generated method stub
            TextReader br = null;
            try
            {
                _cnMap = new HashMap<string, int[]>();
                br = MyStaticValue.GetCompanReader();
                string temp;
                while ((temp = br.ReadLine()) != null)
                {
                    var strs = temp.Split('\t');
                    var cna = new int[2];
                    cna[0] = int.Parse(strs[1]);
                    cna[1] = int.Parse(strs[2]);
                    _cnMap.Add(strs[0], cna);
                }
            }
            finally
            {
                if (br != null)
                    br.Close();
            }
        }
开发者ID:echofool,项目名称:Ansj.Net,代码行数:26,代码来源:CompanyAttrLibrary.cs

示例5: ValueResult

 /// <summary>
 /// </summary>
 /// <param name="smartForest"></param>
 /// <param name="hm"></param>
 /// <param name="nature"></param>
 private void ValueResult(SmartForest<NewWord> smartForest, HashMap<string, double> hm, Nature nature)
 {
     // TODO Auto-generated method stub
     if (smartForest == null || smartForest.Branches == null)
     {
         return;
     }
     for (var i = 0; i < smartForest.Branches.Length; i++)
     {
         var param = smartForest.Branches[i].Param;
         if (smartForest.Branches[i].Status == 3)
         {
             if (param.IsActive && (nature == null || param.Nature.Equals(nature)))
             {
                 hm.Add(param.Name, param.Score);
             }
         }
         else if (smartForest.Branches[i].Status == 2)
         {
             if (param.IsActive && (nature == null || param.Nature.Equals(nature)))
             {
                 hm.Add(param.Name, param.Score);
             }
             ValueResult(smartForest.Branches[i], hm, nature);
         }
         else
         {
             ValueResult(smartForest.Branches[i], hm, nature);
         }
     }
 }
开发者ID:echofool,项目名称:Ansj.Net,代码行数:36,代码来源:LearnTool.cs


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