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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T17:43:31+00:00 2026-05-17T17:43:31+00:00

List<Double> constants = new ArrayList<Double>() {{ add(1.4); add(0.4); add(1.2); add(2.4); add(4.2); add(5); add(6.0); add(7.0);

  • 0
List<Double> constants = new ArrayList<Double>() {{
            add(1.4);
            add(0.4);
            add(1.2);
            add(2.4);
            add(4.2);
            add(5);
            add(6.0);
            add(7.0);           
          }};
  • 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-17T17:43:32+00:00Added an answer on May 17, 2026 at 5:43 pm

    In C# 3.0 or greater,

    var constants = new List<double> { 1.4, 0.4, 1.2, 2.4, 4.2, 5D, 6D, 7D };
    

    constantsis implicitly typed toList<double>with thevarkeyword. The list is initialized (by putting the numbers in braces) using the collection-initializer syntax.

    This is equivalent to (C# 2.0 or greater):

    List<double> constants = new List<double>();
    constants.Add(1.4);
    constants.Add(0.4);
    constants.Add(1.2);
    constants.Add(2.4);
    constants.Add(4.2);
    constants.Add(5D);
    constants.Add(6D);
    constants.Add(7D);
    

    You can leave out theDs, but I prefer to be explicit with numeric literals.

    On another note, if this really represented a list of unnamed constants, it would be good to use an immutable collection such as ReadOnlyCollection<T>. For example:

    var constants = new List<double>{1.4, 0.4, 1.2, 2.4, 4.2, 5, 6, 7}.AsReadOnly();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Consider the following code: List<double> l = new List<double>(); //add unknown number of values
Imagine a doube list like the follow List<double> lstDouble=new List<double>{4,6,2,7,1,1}; So what i want
I am creating a new C# List ( List<double> ). Is there a way,
Now this is example list : List<List<KeyValuePair<string, double>>> dblWordFreqByCluster = new List<List<KeyValuePair<string, double>>>(); What
Consider the following code: Dim arr1 As New List(Of Double) Dim arr2 As New
i have a code like this: List<double[]>t; for(...){ t.Add(elem)}; where 'elem' is a 'double[]',
I'm in the process of creating a double-linked list, and have overloaded the operator=
Where is a complete list of the special double-underscore/dunder methods that can be used
I am storing a list of numbers (as Double) in a text file, then
I have a List where element is: struct element { double priority; int value;

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.