Click here to Skip to main content
15,922,584 members
Home / Discussions / C#
   

C#

 
AnswerRe: How to get the MaxValue using LINQ ?! Pin
Maciej Los29-Apr-19 9:04
mveMaciej Los29-Apr-19 9:04 
GeneralRe: How to get the MaxValue using LINQ ?! Pin
OriginalGriff29-Apr-19 20:14
mveOriginalGriff29-Apr-19 20:14 
PraiseRe: How to get the MaxValue using LINQ ?! Pin
Maciej Los29-Apr-19 20:29
mveMaciej Los29-Apr-19 20:29 
GeneralRe: How to get the MaxValue using LINQ ?! Pin
OriginalGriff29-Apr-19 20:42
mveOriginalGriff29-Apr-19 20:42 
GeneralRe: How to get the MaxValue using LINQ ?! Pin
Luc Pattyn30-Apr-19 0:37
sitebuilderLuc Pattyn30-Apr-19 0:37 
GeneralRe: How to get the MaxValue using LINQ ?! Pin
Richard Deeming1-May-19 8:20
mveRichard Deeming1-May-19 8:20 
QuestionRe: How to get the MaxValue using LINQ ?! Pin
Maciej Los2-May-19 8:24
mveMaciej Los2-May-19 8:24 
AnswerRe: How to get the MaxValue using LINQ ?! Pin
Richard Deeming3-May-19 0:43
mveRichard Deeming3-May-19 0:43 
It doesn't make any difference. There is no Max method on the List<T> type, so you're calling the Enumerable.Max extension method[^]. The overload you're calling returns the maximum projected value, not the item from which that value was projected. There is no overload which would return the item with the highest projected value, so you'd have to use a custom extension method.

Try running it yourself:
C#
public class Foo
{
    public double SecondsDifference { get; set; }
}

static void Main()
{
    List<Foo> foos = new List<Foo>
    {
        new Foo { SecondsDifference = 0 },
        new Foo { SecondsDifference = 42 },
        new Foo { SecondsDifference = 1 },
    };
    
    var max = foos.Max(f => f.SecondsDifference);
    Console.WriteLine(max.GetType()); // Output: System.Double
    Console.WriteLine(max); // Output: 42
}

LINQ Max | C# Online Compiler | .NET Fiddle[^]



"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer

PraiseRe: How to get the MaxValue using LINQ ?! Pin
Maciej Los3-May-19 1:25
mveMaciej Los3-May-19 1:25 
AnswerRe: How to get the MaxValue using LINQ ?! Pin
Maciej Los3-May-19 1:34
mveMaciej Los3-May-19 1:34 
GeneralRe: How to get the MaxValue using LINQ ?! Pin
Abdalla Ben Omran3-May-19 2:30
Abdalla Ben Omran3-May-19 2:30 
Questiondata structure Pin
Member 1434080028-Apr-19 3:35
Member 1434080028-Apr-19 3:35 
AnswerRe: data structure Pin
OriginalGriff28-Apr-19 4:27
mveOriginalGriff28-Apr-19 4:27 
AnswerRe: data structure Pin
Luc Pattyn28-Apr-19 9:59
sitebuilderLuc Pattyn28-Apr-19 9:59 
QuestionHow to find the Max or the Highest value in (List) using just C# code and No LINQ Pin
Abdalla Ben Omran26-Apr-19 5:38
Abdalla Ben Omran26-Apr-19 5:38 
AnswerRe: How to find the Max or the Highest value in (List) using just C# code and No LINQ Pin
#realJSOP26-Apr-19 5:45
professional#realJSOP26-Apr-19 5:45 
GeneralRe: How to find the Max or the Highest value in (List) using just C# code and No LINQ Pin
Abdalla Ben Omran26-Apr-19 23:49
Abdalla Ben Omran26-Apr-19 23:49 
GeneralRe: How to find the Max or the Highest value in (List) using just C# code and No LINQ Pin
#realJSOP27-Apr-19 0:01
professional#realJSOP27-Apr-19 0:01 
GeneralRe: How to find the Max or the Highest value in (List) using just C# code and No LINQ Pin
Abdalla Ben Omran27-Apr-19 0:45
Abdalla Ben Omran27-Apr-19 0:45 
GeneralRe: How to find the Max or the Highest value in (List) using just C# code and No LINQ Pin
Gerry Schmitz27-Apr-19 2:50
mveGerry Schmitz27-Apr-19 2:50 
GeneralRe: How to find the Max or the Highest value in (List) using just C# code and No LINQ Pin
Abdalla Ben Omran27-Apr-19 6:32
Abdalla Ben Omran27-Apr-19 6:32 
GeneralRe: How to find the Max or the Highest value in (List) using just C# code and No LINQ Pin
Richard Deeming1-May-19 8:13
mveRichard Deeming1-May-19 8:13 
AnswerRe: How to find the Max or the Highest value in (List) using just C# code and No LINQ Pin
Richard Deeming26-Apr-19 5:55
mveRichard Deeming26-Apr-19 5:55 
QuestionHow to get an Not Empty Instance back ? Pin
Abdalla Ben Omran26-Apr-19 2:42
Abdalla Ben Omran26-Apr-19 2:42 
AnswerRe: How to get an Not Empty Instance back ? Pin
Richard Deeming26-Apr-19 3:14
mveRichard Deeming26-Apr-19 3:14 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.