为了账号安全,请及时绑定邮箱和手机立即绑定

C# 怎么提供像字典Dictionary那样的初始化方法

C# 怎么提供像字典Dictionary那样的初始化方法

C#
心有法竹 2018-07-28 16:04:04
new Dictionary<string, string>             {                 {"a","n" },                 {"b","n" },                 {"c","n" },                 {"d","n" },                 {"e","n" },                 {"f","n" },             };

2 回答

?
繁星coding

TA贡献1797条经验 获得超4个赞

public class TestA<Tkey,TValue> :IEnumerable<Tkey>
    {      
        public void Add(Tkey key,TValue value)
        {

        }        public IEnumerator<Tkey> GetEnumerator()
        {            throw new NotImplementedException();
        }

        IEnumerator IEnumerable.GetEnumerator()
        {            throw new NotImplementedException();
        }
    }

用ILSpy看下Dictionary就可以了。

查看完整回答
反对 回复 2018-07-30
?
郎朗坤

TA贡献1921条经验 获得超9个赞

这个初始化方式叫做属性构造器。

查看完整回答
反对 回复 2018-07-30

添加回答

代码语言

举报

0/150
提交
取消
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号