Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1044139
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T15:46:46+00:00 2026-05-16T15:46:46+00:00

I need to initialize a bunch of lists and populate them with lots of

  • 0

I need to initialize a bunch of lists and populate them with lots of values during initialization, but csc 2.0 compiler that i have to use doesn’t like it. For example:

List<int> ints = new List<int>() { 1, 2, 3 };

will produce the following compiler error:

error CS1002: ; expected

Is there a way to initialize a list that will make csc 2.0 compiler happy without doing something ugly like this:

List<int> ints = new List<int>();
ints.Add(1);
ints.Add(2);
ints.Add(3);
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T15:46:47+00:00Added an answer on May 16, 2026 at 3:46 pm

    You’re using a feature called collection initializers which was added in C# 3.0 and hence is not present in the C# 2.0 compiler. The closest you will get syntax wise is using an explicit array passed to the List<T> constructor.

    List<int> ints = new List<int>(new int[] { 1, 2, 3 });
    

    Note: This approach produces substantially different code than the C# collection initializer version.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some classes that need a bunch of data tables to do their
I have a class level NSMutableDictionary object that I need to initialize, and reinitialize.
I'm writing a web application and need to initialize some parameters that I'm pulling
I have a class: class One def initialize; end end I need to create
In my tableview, I need a bunch (5-6 types) of different cells. All have
I need to initialize a set of static String values stored in an XML
guys! I have a problem. I need to initialize my sortable() with items 'li:not(.someclass)'.
I found that in C language but I don't know other language it need
I have an application where I need to initialize the contentOffset of a UIScrollView
I need to initialize a session var as array. Where i do that? when

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.