{} vs [] when initializing an array in C#
Hello guys, is there a difference when we use
{}
to initialize an array or if we use []
? I read that the []
is known as a collection expression.
4 Replies
the second one is a newer way to do it, but they do the same thing in these examples
the
[]
way can be used with lists and other collection types as wellyep I see, it's better to just stick with the newer syntax?
it doesn't really matter, but if you want to be consistent then the newer syntax can be used in more places
ok noted, ty