473,405 Members | 2,185 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

Initializing a collection

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<stringanimals = 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?
Sep 5 '06 #1
3 1569
I've never heard of a collection initialization list, so I would say they
are misled. Where did you find the code sample?

/claes
"michael sorens" <m_********@community.nospamwrote in message
news:op***************@spo-cont-2-dt.itron.com...
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<stringanimals = 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?
Sep 5 '06 #2
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]
- mv*@spam.guard.caspershouse.com

"michael sorens" <m_********@community.nospamwrote in message
news:op***************@spo-cont-2-dt.itron.com...
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<stringanimals = 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?
Sep 5 '06 #3
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/re.../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/subscripti...ult.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/subscripti...t/default.aspx.
==================================================

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

Sep 6 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Ray Mitchell | last post by:
Hello, I've created a 2-column listView control and have successfully labeled the column headers using the ColumnHeader Collection editor. I would now like to put some text items into the list...
7
by: GrandpaB | last post by:
While writing this plea for help, I think I solved my dilemma, but I don't know why the statement that solved the problem is necessary. The inspiration for the statement came from an undocumented...
5
by: ScottM | last post by:
I expect this has been covered somewhere, but I can't find it. Given: class A { public: A() {...does stuff...} }; struct S { A a; };
8
by: SM | last post by:
I've always wonder if there is diference when declaring and initializing a varible inside/outside a loop. What's a better practice? Declaring and initializing variables inside a loop routine,...
6
by: moo | last post by:
Forgive the fairly mundane question, but all the code samples I've found searching for initializing a dictionary have only shown one way, specifically: <code> HybridDictionary toy = new...
38
by: junky_fellow | last post by:
Guys, I was just looking at some code where to initialize an integer with all F's following statement is used; unsigned int i = -1; I want to know if this is the right way of doing the...
13
by: WaterWalk | last post by:
Hello. When I consult the ISO C++ standard, I notice that in paragraph 3.6.2.1, the standard states: "Objects with static storage duration shall be zero-initialized before any other...
8
by: Sin Jeong-hun | last post by:
Is there any way to initialize an array of objects without looping through each elements? Class A { private int PrivateValue; public A(int a) { PrivateValue=a; }
2
by: steve | last post by:
I have the very simple derived class below but when I drag the class from the toolbox on to one of my UserControls VS designer extracts the information and puts it into its resource database for the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.