本文整理汇总了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}");
}
}
示例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();
}
}
示例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);
}
}
}
示例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();
}
}
示例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);
}
}
}