为什么你可以在集合初始化的最后一个逗号? [英] Why can you have a comma at the end of a collection initializer?
本文介绍了为什么你可以在集合初始化的最后一个逗号?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这其中一直困惑我,但我猜有它为什么会发生一个非常明智的解释。
当你有一个集合初始化编译器允许一个结尾逗号,例如
新字典<字符串,字符串>
{
{富,酒吧},
};
和
新的List<串GT;
{
富,
};
任何人都知道为什么这个结尾的逗号是由编译器允许的?
< DIV CLASS =h2_lin>解决方案
类似理由的 http://stackoverflow.com/questions/2147333/net-enumeration-allows-comma-in-the-last-field
This one has always puzzled me, but i'm guessing there is a very sensible explanation of why it happens.
When you have a collection initializer the compiler allows a trailing comma, e.g.
new Dictionary<string, string>
{
{ "Foo", "Bar "},
};
and
new List<string>
{
"Foo",
};
Anyone know why this trailing comma is allowed by the compiler?
解决方案
Similar reason to http://stackoverflow.com/questions/2147333/net-enumeration-allows-comma-in-the-last-field
这篇关于为什么你可以在集合初始化的最后一个逗号?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文