Click here to Skip to main content
16,004,828 members
Home / Discussions / C#
   

C#

 
AnswerRe: Traffic laws Project Pin
Dave Kreskowiak19-Jan-15 4:38
mveDave Kreskowiak19-Jan-15 4:38 
AnswerRe: Traffic laws Project Pin
Afzaal Ahmad Zeeshan19-Jan-15 5:03
professionalAfzaal Ahmad Zeeshan19-Jan-15 5:03 
AnswerRe: Traffic laws Project Pin
V.20-Jan-15 1:59
professionalV.20-Jan-15 1:59 
Questionaugmenting reality project (Affix Center Sofech Services Pvt. Ltd) Pin
ishaan279118-Jan-15 23:13
ishaan279118-Jan-15 23:13 
AnswerRe: augmenting reality project (Affix Center Sofech Services Pvt. Ltd) Pin
OriginalGriff18-Jan-15 23:23
mveOriginalGriff18-Jan-15 23:23 
QuestionThe Max() linq extension method on a List<MyClass> [Solved] Pin
TMattC18-Jan-15 23:06
TMattC18-Jan-15 23:06 
AnswerRe: The Max() linq extension method on a List<MyClass> Pin
TMattC18-Jan-15 23:16
TMattC18-Jan-15 23:16 
AnswerRe: The Max() linq extension method on a List<MyClass> Pin
Richard Deeming18-Jan-15 23:19
mveRichard Deeming18-Jan-15 23:19 
If you only want the value of the maximum ID, you can use either:
C#
int maxId = lst.Select(x => x.Id).Max();

or:
C#
int maxId = lst.Max(x => x.Id);

If you want to get the instance of MyClass which has the maximum ID, you'll need to implement the IComparable<T> interface[^]:
C#
public class MyClass : IComparable<MyClass>
{
    public int Id { get; set; }
    
    public MyClass(int _id)
    { 
        Id = _id; 
    }
    
    public int CompareTo(MyClass other)
    {
        if (other == null) return 1;
        return Id.CompareTo(other.Id);
    }
}
...
MyClass maxId = lst.Max();

Unfortunately, there isn't an overload which takes an IComparer<T> instance[^], so if you need different sort orders in different situations, you're stuck with writing your own Max method.



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


QuestionSignalR - Realtime events - Database communication - thoughts? Pin
Angelika S Michel17-Jan-15 16:39
Angelika S Michel17-Jan-15 16:39 
AnswerRe: SignalR - Realtime events - Database communication - thoughts? Pin
Eddy Vluggen19-Jan-15 8:08
professionalEddy Vluggen19-Jan-15 8:08 
GeneralRe: SignalR - Realtime events - Database communication - thoughts? Pin
Angelika S Michel21-Jan-15 7:21
Angelika S Michel21-Jan-15 7:21 
GeneralRe: SignalR - Realtime events - Database communication - thoughts? Pin
Eddy Vluggen21-Jan-15 8:08
professionalEddy Vluggen21-Jan-15 8:08 
Questioni want to show these combo bax on select index!!!!!!!!!! Pin
hari om singh16-Jan-15 21:21
hari om singh16-Jan-15 21:21 
AnswerRe: i want to show these combo bax on select index!!!!!!!!!! Pin
Wendelius16-Jan-15 21:42
mentorWendelius16-Jan-15 21:42 
GeneralRe: i want to show these combo bax on select index!!!!!!!!!! Pin
hari om singh16-Jan-15 21:47
hari om singh16-Jan-15 21:47 
GeneralRe: i want to show these combo bax on select index!!!!!!!!!! Pin
Wendelius16-Jan-15 22:07
mentorWendelius16-Jan-15 22:07 
GeneralRe: i want to show these combo bax on select index!!!!!!!!!! Pin
hari om singh16-Jan-15 22:09
hari om singh16-Jan-15 22:09 
GeneralRe: i want to show these combo bax on select index!!!!!!!!!! Pin
OriginalGriff16-Jan-15 22:18
mveOriginalGriff16-Jan-15 22:18 
GeneralRe: i want to show these combo bax on select index!!!!!!!!!! Pin
hari om singh16-Jan-15 22:27
hari om singh16-Jan-15 22:27 
GeneralRe: i want to show these combo bax on select index!!!!!!!!!! Pin
Wendelius16-Jan-15 23:18
mentorWendelius16-Jan-15 23:18 
GeneralRe: i want to show these combo bax on select index!!!!!!!!!! Pin
OriginalGriff16-Jan-15 23:30
mveOriginalGriff16-Jan-15 23:30 
GeneralRe: i want to show these combo bax on select index!!!!!!!!!! Pin
Wendelius16-Jan-15 23:38
mentorWendelius16-Jan-15 23:38 
Questionhow to get popup window's infomation with webbrowser? Pin
kidult16-Jan-15 14:37
kidult16-Jan-15 14:37 
AnswerRe: how to get popup window's infomation with webbrowser? Pin
Richard Andrew x6416-Jan-15 14:59
professionalRichard Andrew x6416-Jan-15 14:59 
GeneralRe: how to get popup window's infomation with webbrowser? Pin
kidult16-Jan-15 15:13
kidult16-Jan-15 15:13 

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.