双11狂欢大促

盲盒赢 定制羽绒服

开启惊喜盲盒,抽取你的专属好礼

— 惊喜奖品抢先看 —

请教下 hashmap怎么使用?

unhappyless_23 unhappyless_23 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
是键值对吗?不允许一对多?可以通过键找值,反过来呢?这容器里的对象不要求同一类型吧?给他添加一个元素不一定要 Add 吧?直接给个索引赋值就行了吧?


using System;
using System.Collections;
class IndexClass
{

Hashtable aa = new Hashtable();

public string this[int index]
{
get
{

return aa[index].ToString();
}
set
{

//aa[index] = value; //直接赋值
aa.Add(index, value);
}
}

public int this[ string index]
{
get
{
return (int)aa[index];
}
set
{
// aa[index] = value;
aa.Add(index, value);

}
}
}

class Test_3
{
static void Main()
{
IndexClass ic = new IndexClass();

ic["1"] = 2;
ic[3] = "1";
Console.WriteLine(ic["1"]);
Console.WriteLine(ic[3]);
}
}
...全文

相关推荐

评论 6
收藏 已收藏
分享
返回顶部
unhappyless_23
C# 111,129 成员 642,540 内容