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

  • Home
  • SEARCH
  • 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 6631737
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T22:35:18+00:00 2026-05-25T22:35:18+00:00

This: List<string> set = new List<string>() { a,b }; works fine, but: Stack<string> set

  • 0

This:

List<string> set = new List<string>() { "a","b" };

works fine, but:

Stack<string> set = new Stack<string>() { "a","b" };
Queue<string> set = new Queue<string>() { "a","b" };

fails with:

...does not contain a definition for 'Add'

which does make me wonder why the compiler was dumb enough to ask for Add.

So, how should one initialise at a Queue/Stack constructor?

  • 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-25T22:35:18+00:00Added an answer on May 25, 2026 at 10:35 pm

    Collection initializers are a compiler feature that call the Add method with each item you pass.
    If there is no Add method, you can’t use it.

    Instead, you can call the Stack or Queue constructor that takes an IEnumerable<T>:

    var stack = new Stack<int>(new [] { 1, 2, 3 });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a list like this Dim emailList as new List(Of String) emailList.Add(one@domain.com) emailList.Add(two@domain.com)
When I enter a string that it not in the list, I get this
I have a collection like this List<int> {1,15,17,8,3}; how to get a flat string
I know I can loop through a list of strings like this: list<string>::iterator Iterator;
I have a String List with items like this Root Root/Item1 Root/Item2 Root/Item3/SubItem1 Root/Item3/SubItem2
considering this example: public static void main(final String[] args) { final List<String> myList =
I have a string like this: TEST.DATA.Data.COR.Point,2;TEST.DATA.Data.COR.Point,5;TEST.DATA.Data.COR.Point,12;TEST.DATA.Data.COR.Point,12;TEST.DATA.Data.COR.WordTOFIND,18 I have a list of array with
is there a way to do this with automatic properties ? private IList<string> List;
How come anonymous functions works as arguments on methods, but not in constructor arguments?
Assuming these objects... class MyClass { int ID {get;set;} string Name {get;set;} List<MyOtherClass> Things

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.