---
title: "Use SingleOrDefault in Linq."  
description: "Use SingleOrDefault in Linq."  
author: "Norman Reedus"  
published: 2016-03-18  
updated: 2016-03-18  
canonical: https://www.mindstick.com/forum/34064/use-singleordefault-in-linq  
category: "linq"  
tags: ["c#", "linq"]  
reading_time: 1 minute  

---

# Use SingleOrDefault in Linq.

We want to use [SingleOrDefault](https://www.mindstick.com/forum/161157/what-are-the-linq-single-and-singleordefault-functions) in Linq. how to use this please help me.

## Replies

### Reply by Anonymous User

**SingleOrDefault** is similar to Single. On empty collections, it returns the default value for the type. With it you receive the single matching element, or the default value if no element is found.

```
using System;using System.Collections.Generic;using System.Linq;using System.Text;namespace Prototype{    class Example    {
        static void Main()        {            int[] array = { 1, 2, 3,4,5,6,7,8,9 };            // Default is returned 0 if no element found.            int a = array.SingleOrDefault(element => element == 10);            Console.WriteLine(a);            // Value is returned if one is found.            int b = array.SingleOrDefault(element => element == 8);            Console.WriteLine(b);            Console.ReadLine();        }    }
}
```

![Use SingleOrDefault in Linq.](https://www.mindstick.com/mindstickforums/983d758e-0980-495f-b3e2-3066099ed84d/images/77759b6b-c973-4bc6-8beb-563b4a924e2a.png)


---

Original Source: https://www.mindstick.com/forum/34064/use-singleordefault-in-linq

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
