首页 新闻 赞助 找找看

C#代码问题

0
[已关闭问题] 关闭于 2016-09-09 20:42
var tb = new Dictionary<KeyValuePair<int, int>, int>();
if (d1 == 0)
{
    tb[new KeyValuePair<int, int>(h - 1, d2 + 11)] = 1;
}
else if (d1 == 1)
{
    tb[new KeyValuePair<int, int>(h - 1, d2 + 20)] = 1;
}
else if (d1 == 2)
{
    tb[new KeyValuePair<int, int>(h - 1, d2 + 29)] = 1;
}
else if (d1 == 3)
{
    tb[new KeyValuePair<int, int>(h - 1, d2 + 38)] = 1;
}
... ...
... ...

新手练习小功能,各位大神帮忙看看,代码可以优化不?太多的new KeyValuePair<int, int>要怎么处理呀?

梦天涯的主页 梦天涯 | 初学一级 | 园豆:103
提问于:2016-09-08 12:05
< >
分享
所有回答(4)
3
tb[new KeyValuePair<int, int>(h - 1, d2 + 11 + d1 * 9)] = 1;

 

RosonJ | 园豆:4910 (老鸟四级) | 2016-09-08 12:28
0

用KeyValuePair当key合适么

nil | 园豆:879 (小虾三级) | 2016-09-08 16:18
0

分离出去,单独写一个方法应该可以

不要问我从哪里来123 | 园豆:6 (初学一级) | 2016-09-08 16:36
0

这样写好奇怪...

思路有问题...

KeyValuePair当作为Dictionary的key有不好..

cotopboy | 园豆:229 (菜鸟二级) | 2016-09-08 23:16
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册