Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Min number in list > SomeNumber

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Min number in list > SomeNumber

    I'm struggling to find the smallest number from a list of Double numbers that is greater than another number.

    EXAMPLE:
    List (30, 38, 40, 50, 56)
    SomeNumber = 35
    Want to return 38

    I know there is something like this:
    var list = new[] {30 ,38, 40, 50, 56};
    MinNumber = list.Min();

    but how do I fit the condition of greater than SomeNumber in there?

    Thanks!​

    #2
    Hello nelslynn,

    Make a new list of numbers that meet the criteria then use the <Enumerable>.Min().



    list.Where( num => num > SomeNumber ).Min()
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Here's what I came up with based on the references you gave. Can I not use this with double numbers?

      List<double> MyList= new List<double> {30, 38.223, 40, 50, 56.23};

      IEnumerable<double> query = MyList.Where(MyList < SomeNumber);
      MyValue = query.Min();

      I get this error:
      Operator '<' cannot be applied to operands of type 'List<double> and 'double'​

      Comment


        #4
        Hello nelslynn,

        It looks like you have changed the name of the 'list' variable to 'MyList'. The updated code would appear:

        MyList.Where( num => num > SomeNumber ).Min()

        See post # 2 where I have made this suggestion.


        "Can I not use this with double numbers?"

        A List<double> is a collection of multiple values.

        A double is one value.

        You cannot compare an entire collection of values to one value.

        Instead use the code I have suggested, which is comparing each value in the collection, one at a time, held by the 'num' variable, to the 'SomeNumber' double variable.
        Chelsea B.NinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by NullPointStrategies, Today, 05:17 AM
        0 responses
        53 views
        0 likes
        Last Post NullPointStrategies  
        Started by argusthome, 03-08-2026, 10:06 AM
        0 responses
        130 views
        0 likes
        Last Post argusthome  
        Started by NabilKhattabi, 03-06-2026, 11:18 AM
        0 responses
        70 views
        0 likes
        Last Post NabilKhattabi  
        Started by Deep42, 03-06-2026, 12:28 AM
        0 responses
        44 views
        0 likes
        Last Post Deep42
        by Deep42
         
        Started by TheRealMorford, 03-05-2026, 06:15 PM
        0 responses
        49 views
        0 likes
        Last Post TheRealMorford  
        Working...
        X