I am using NameValueCollection
to store values that I will post to API server later. Today I accidentally added extra comma when I initialize an instance of NameValueCollection
like simple code below:
NameValueCollection nvc = new NameValueCollection()
{
["foo"] = "bar",
["hello"] = "world", // <-- an extra comma here
};
Note that there is extra comma after world
value. This code compiles normally on my computer and other dev's computer, with or without extra comma. But I can't manage it to run on .NET Fiddle even using the right code. I'm using .NET 4.6.1 if it matters.
I am aware of different way to initialize NameValueCollection
like on fiddle above, but it's not the problem/question. My question is, why can the compiler compile this broken code and not issue some warning? Or maybe my Visual Studio settings are incorrect in somewhere? Or I am missing some coding principle? Please advice. Thank you.