2
Reply

What is differance between first and single in linq

vinay khanna

vinay khanna

4y
2.6k
0
Reply

    Single()

    1. Returns a single specific element of a query
    2. When Use: If exactly 1 element is expected; not 0 or more than 1. If the list is empty or has more than one element, it will throw an Exception “Sequence contains more than one element”

    First()

    1. Returns the first element of a query with multiple results.
      2. When Use: When 1 or more elements are expected and you want only the first. It will throw an exception if the list contains no elements.

    single throw an exception when query results more than a record but first results first item of a collection