Can't create and initialize list (or hashtable) in one statement...?!

  • Thread starter Thread starter Big Bird
  • Start date Start date
B

Big Bird

System.Collections.Hashtable h = new System.Collections.Hashtable() {
null };

Complains about ";" being expected after '()'.

Using Visual Studio 2005. What's going on?
 
Big Bird said:
System.Collections.Hashtable h = new System.Collections.Hashtable() {
null };

Complains about ";" being expected after '()'.

Using Visual Studio 2005. What's going on?

What are you expecting the above to do? If you're expecting to use
C# 3's collection initializers, that's part of C# 3 rather than C# 2,
so you can't do it in VS 2005.
 
Big said:
System.Collections.Hashtable h = new System.Collections.Hashtable() {
null };

Complains about ";" being expected after '()'.

Using Visual Studio 2005. What's going on?

for a list, you can do this:

List<T> list = new List<T>(new T[] { elem1, elem2, elem3, elem4 });
 

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