How to get first object out from ListObject using Linq
Data Structures & Algorithms practice on Codemia
Step through 300 algorithm problems with animated visualisers that show the data structure changing as the code runs.
Introduction
If you want the first object from a List<T> using LINQ, the usual methods are First() and FirstOrDefault(). They look similar, but they differ in how they behave when the sequence is empty, and that difference matters more than the retrieval itself.
Use First() When an Element Must Exist
First() returns the first element in the sequence and throws an exception if the list is empty.
This is appropriate when an empty list would represent a bug or an invalid application state.
Use FirstOrDefault() When Empty Is Acceptable
FirstOrDefault() returns the first element if one exists. Otherwise it returns the default value for the type.
For reference types, the default is null. That makes FirstOrDefault() safer for optional lookup patterns, but it also means you need to think about what the default value means in your program.
Filtering Before Taking the First Match
LINQ becomes especially useful when you want the first element matching a condition.
This is often clearer than manually writing a loop for one simple query.
Compare with Index Access
If you only need the first element of a list and you already know it is a List<T>, direct index access also works:
That avoids LINQ overhead, but it throws ArgumentOutOfRangeException when the list is empty. In everyday application code, the bigger decision is usually readability and empty-sequence behavior, not micro-optimization.
Choose the Method by Intent
A useful rule is:
- use
First()when absence is exceptional, - use
FirstOrDefault()when absence is normal and should be handled, - use index access when you are working with a concrete list and want direct positional semantics.
That makes the code communicate what the caller expects from the collection.
Single() Is a Different Contract
Developers sometimes confuse First() with Single(). First() means "give me the first match." Single() means "there must be exactly one match." If you only want the first element in a list, Single() expresses a much stronger requirement and will throw if more than one element exists.
Common Pitfalls
- Using
First()on data that can legitimately be empty. - Using
FirstOrDefault()and then forgetting to handlenullor the default value. - Treating
0fromFirstOrDefault()on a numeric list as though it proved an element existed. - Reaching for LINQ when plain index access is clearer in a tightly controlled list context.
- Writing a predicate query and assuming a match must exist without checking that assumption.
Summary
First()returns the first item and throws if the sequence is empty.FirstOrDefault()returns the first item or the type’s default value.- Predicate overloads let you ask for the first matching object, not only the first positional element.
- The important choice is how your code should behave when no element exists.
- Good LINQ usage is about expressing intent clearly, not only shortening syntax.
- Small API choices can carry significant semantic meaning.
Related reading
- How to get indices of a sorted array in Python
- How to get IntPtr from byte in C
- How to get largest number of consecutive integers in a substantially large array (spread across multiple machines)
- How to get last items of a list in Python?
- How to get index using LINQ?
- How to get json response using system.net.webrequest in c?
- how to get longest repeating string in substring from suffix tree
- How to get Spring RabbitMQ to create a new Queue?

DSA Fundamentals
Master algorithmic patterns and data structures through hands-on LeetCode-style problems - from arrays and hashing to dynamic programming and advanced graphs.
View the courseTrack what you have practised
A free account saves your progress, solutions and study plan across every problem on Codemia.
Data Structures & Algorithms practice on Codemia
Step through 300 algorithm problems with animated visualisers that show the data structure changing as the code runs.