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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T03:16:56+00:00 2026-06-12T03:16:56+00:00

What am I missing here? I expected the following to work just fine: public

  • 0

What am I missing here? I expected the following to work just fine:

public class ProposalFileInfo
{
    public int FileId { get; set; }
    public bool IsSupportDocument { get; set; }
}

// ...

var attachments = new List<ProposalFileInfo>();

attachments.Add(new ProposalFileInfo { 1, false });
attachments.Add(new ProposalFileInfo { 2, false });
attachments.Add(new ProposalFileInfo { 3, false });

Instead I get an error at the { character on each of the last three lines:

Cannot initialize type ‘xxx.yyy.ProposalFileInfo’ with a collection initializer because it does not implement ‘System.Collections.IEnumerable’

Am I not using an Object initializer? Why does it assume a collection initializer? (I’m using Visual Studio 2012.)

  • 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-06-12T03:16:58+00:00Added an answer on June 12, 2026 at 3:16 am

    To use an object initializer you have to specify which properties you want to set:

    attachments.Add(new ProposalFileInfo { FileId = 1, IsSupportDocument = false });
    

    So converting your whole initialization into a collection initializer, we end up with:

    var attachments = new List<ProposalFileInfo>
    {
        new ProposalFileInfo { FileId = 1, IsSupportDocument = false },
        new ProposalFileInfo { FileId = 2, IsSupportDocument = false },
        new ProposalFileInfo { FileId = 3, IsSupportDocument = false },
    };
    

    However, you could make your code simpler by simply adding a constructor to ProposalFileInfo:

    public ProposalFileInfo(int fileId, bool isSupportDocument)
    {
        FileId = fileId;
        IsSupportDocument = isSupportDocument;
    }
    

    Then your initialization can just be:

    var attachments = new List<ProposalFileInfo>
    {
        new ProposalFileInfo(1, false),
        new ProposalFileInfo(2, false),
        new ProposalFileInfo(3, false)
    };
    

    If you feel you want to specify what each argument means (or some of them), and you’re using C# 4, you can use named arguments, e.g.

        new ProposalFileInfo(1, isSupportDocument: false),
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

What am I missing here? ViewModel: public class ViewModel { public IDictionary<int, string> Entities
I need help making AOP work. What am I missing here? <?xml version=1.0 encoding=UTF-8?>
If I run the following test, it fails: public class CrazyExceptions { private Exception
I'm surely missing something here, as what I expect to work identically, is working
I'm currently getting the following compile errors: In function 'int main()': error: expected primary-expression
What am I missing here? This is the error I am getting... error: type
Wondering what I'm missing here. Relatively new to C and iOS development, so please
What am I missing here? I am using the haml_scaffold generator and the pages
not sure what I'm missing here, but i keep getting the error. SQLSTATE[HY093]: Invalid
Is there some trick that I'm missing here? I've created a templated control, very

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.