This topic has been archived. It cannot be replied.
-
工作学习 / 学科技术讨论 / 我的头儿写的C#, 对吗?.
.
.
List<string> groups = new List<string>();
if (currentElm.Groups != null && currentElm.Groups.Length > 0)
groups = new List<string>(currentElm.Groups);
.
.
.
-tonyhao(tonyhao);
2010-4-24
{172}
(#6031140@0)
-
没有上下文, 加了很多猜测后, 我觉得是对的, 只是GROUPS这个变量初始化了两次, 小小浪费了资源. 在REVIEW的时候应该纠正.
-youbet(寻常巷陌);
2010-4-24
(#6032230@0)
-
跟上下文没关系, 如果条件成立, 那么就是new了2次
-tonyhao(tonyhao);
2010-4-25
(#6032625@0)
-
List<string> groups = currentElm.Groups == null ?new List<string>() :new List<string>(currentElm.Groups);这么写怎么样?
-c1xwy(洪兴罩俺去战斗);
2010-4-24
(#6032276@0)
-
或者条件语句里改为groups.AddRange(currentElm.Groups); 就可以了。
-wangqingshui(忘情水);
2010-4-25
(#6032642@0)
-
I cannot see any thing wrong. If there value, fill value into the object. otherwise, just init a empty object.
-deep_blue(BLUE);
2010-4-25
(#6033113@0)
-
the code works well. Just a little confused. If it is right, that's fine.
-tonyhao(tonyhao);
2010-4-26
(#6034914@0)