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 349611
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T11:28:28+00:00 2026-05-12T11:28:28+00:00

in C# 3, initializers were added. This is a great feature. However, one thing

  • 0

in C# 3, initializers were added. This is a great feature. However, one thing has me confused.

When you initialize class, you typically have to specify the member variable or property you are initializing. For example:

class C { public int i; }

public void blah() {
    C c = new C() { i = 1 };
}

Array semantics have been in C# since the beginning, i think. But they don’t behave like that. For example

public void foo()
{
    int[] i = new int[] { 0, 1, 2, 3 };
}

All fine and good, but what about classes with array semantics?

public void bar()
{
    List<int> li = new List<int>() { 0, 1, 3, 3 };
}

List is just a class, like any other (though it is a generic).

I’m trying to figure out how the compiler initializes the List member. Is this some kind of magic done behind the scenes? Or is this something related to there being an indexer defined on the class?

Thanks.

  • 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-12T11:28:29+00:00Added an answer on May 12, 2026 at 11:28 am

    C# Language Specification v3.0 Section 7.5.10.3 Collection Initializers:

    The collection object to which a collection initializer is applied must be of a type that implements System.Collections.IEnumerable or a compile-time error occurs. For each specified element in order, the collection initializer invokes an Add method on the target object with the expression list of the element initializer as argument list, applying normal overload resolution for each invocation. Thus, the collection object must contain an applicable Add method for each element initializer.

    To enable this feature for your own collections, you just need to have an Add method with appropriate parameters. The compiler will transform it to a sequence of calls to the Add method with the arguments you specified.

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

Sidebar

Ask A Question

Stats

  • Questions 181k
  • Answers 181k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer What I think you should do Do not attempt to… May 12, 2026 at 4:11 pm
  • Editorial Team
    Editorial Team added an answer The slowness that you're seeing can probably be attributed to… May 12, 2026 at 4:11 pm
  • Editorial Team
    Editorial Team added an answer OpenSSH≥4.8 supports a ChrootDirectory directive. Add to /etc/sshd_config or /etc/ssh/sshd_config… May 12, 2026 at 4:11 pm

Related Questions

Given (in C++) char * byte_sequence; size_t byte_sequence_length; char * buffer; size_t N; Assuming
I am writing an iPhone 3.0 application that uses Core Data to persist the
I take care of critical app in my project. It does stuff related to
Before I have the audacity to file a bug report, I thought I'd check

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.