Initializing a collection

  • Thread starter Thread starter michael sorens
  • Start date Start date
M

michael sorens

I have seen a few references on the internet on a terse way to initialize
a collection, each of which presents a code sample similar to this:

List<string> animals = new List<string> {
"monkey", "donkey", "cow", "dog", "cat" } ;


But that does not compile under my version of Visual Studio 2005. Are
these folks just misled, or am I missing something here?
 
Michael,

That's because this syntax is being used for C# 3.0, which hasn't been
released yet. There is a CTP preview though which you can use. You should
be able to find it on the MSDN site.

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

I have seen a few references on the internet on a terse way to initialize
a collection, each of which presents a code sample similar to this:

List<string> animals = new List<string> {
"monkey", "donkey", "cow", "dog", "cat" } ;


But that does not compile under my version of Visual Studio 2005. Are
these folks just misled, or am I missing something here?
 
I've never heard of a collection initialization list, so I would say they
are misled. Where did you find the code sample?

/claes


I have seen a few references on the internet on a terse way to initialize
a collection, each of which presents a code sample similar to this:

List<string> animals = new List<string> {
"monkey", "donkey", "cow", "dog", "cat" } ;


But that does not compile under my version of Visual Studio 2005. Are
these folks just misled, or am I missing something here?
 
Hi Michael,

I agree with what Nicholas said that this syntax of collection initializer
is put forward in C# 3.0 specification, which has not been released yet.

For more proposed features of C# 3.0, you may refer to the link as follows.

http://msdn.microsoft.com/vstudio/reference/default.aspx?pull=/library/en-us
/dnvs05/html/cs3spec.asp

Hope this helps.


Sincerely,
Linda Liu
Microsoft Online Community Support

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top