16
Reply

What is the difference between First() and FirstOrDefault() selector methods in LINQ?

Nilesh Shah

Nilesh Shah

Feb 01, 2017
3.4k
3

    First() always expects at least one element in result set, if there isn't any element is result, then First() returns an exception. While FirstOrDefault() is fine with a result set having 0 elements, it does not throw any exception

    Nilesh Shah
    February 01, 2017
    9

    First() :- it always find at least one value from result set. if no value or more than one value then it will through exception. FirstOrDefault() :- return the first element from sequence or return the default value from result set. if no element is found then it will through exception.

    sushil kumar
    July 14, 2017
    1

    Hi First() throw an exception when there is no record where as FirstOrDefault () does not throw an exception.So we can say First() does not support Null value where as FirstOrDefault support Null values

    RAHUL SHUKLA
    June 23, 2017
    1

    @Rahul I see your multiple and same replies, keep only one and delete others

    Nilesh Shah
    June 23, 2017
    0

    Hi First() throw an exception when there is no record where as FirstOrDefault () does not throw an exception.So we can say First() does not support Null value where as FirstOrDefault support Null values

    RAHUL SHUKLA
    June 23, 2017
    0

    Hi First() throw an exception when there is no record where as FirstOrDefault () does not throw an exception.So we can say First() does not support Null value where as FirstOrDefault support Null values

    RAHUL SHUKLA
    June 23, 2017
    0

    Hi First() throw an exception when there is no record where as FirstOrDefault () does not throw an exception.So we can say First() does not support Null value where as FirstOrDefault support Null values

    RAHUL SHUKLA
    June 23, 2017
    0

    Hi First() throw an exception when there is no record where as FirstOrDefault () does not throw an exception.So we can say First() does not support Null value where as FirstOrDefault support Null values

    RAHUL SHUKLA
    June 23, 2017
    0

    Hi First() throw an exception when there is no record where as FirstOrDefault () does not throw an exception.So we can say First() does not support Null value where as FirstOrDefault support Null values

    RAHUL SHUKLA
    June 23, 2017
    0

    Hi First() throw an exception when there is no record where as FirstOrDefault () does not throw an exception.So we can say First() does not support Null value where as FirstOrDefault support Null values

    RAHUL SHUKLA
    June 23, 2017
    0

    Hi First() throw an exception when there is no record where as FirstOrDefault () does not throw an exception.So we can say First() does not support Null value where as FirstOrDefault support Null values

    RAHUL SHUKLA
    June 23, 2017
    0

    Hi First() throw an exception when there is no record where as FirstOrDefault () does not throw an exception.So we can say First() does not support Null value where as FirstOrDefault support Null values

    RAHUL SHUKLA
    June 23, 2017
    0

    Hi First() throw an exception when there is no record where as FirstOrDefault () does not throw an exception.So we can say First() does not support Null value where as FirstOrDefault support Null values

    RAHUL SHUKLA
    June 23, 2017
    0

    Hi First() throw an exception when there is no record where as FirstOrDefault () does not throw an exception.So we can say First() does not support Null value where as FirstOrDefault support Null values

    RAHUL SHUKLA
    June 23, 2017
    0

    Hi First() throw an exception when there is no record where as FirstOrDefault () does not throw an exception.So we can say First() does not support Null value where as FirstOrDefault support Null values

    RAHUL SHUKLA
    June 23, 2017
    0

    First()- their are at least one element in sequence FirstOrDefault()- you are checking wither their is any element in sequence.

    Naveen Bisht
    February 16, 2017
    0