---
title: "Default Value when using SingleOrDefault()"  
description: "Default Value when using SingleOrDefault()"  
author: "Manoj Bhatt"  
published: 2015-03-17  
updated: 2015-03-17  
canonical: https://www.mindstick.com/forum/23023/default-value-when-using-singleordefault  
category: ".net"  
tags: ["c#", "linq"]  
reading_time: 1 minute  

---

# Default Value when using SingleOrDefault()

I have a [simple](https://yourviews.mindstick.com/story/1469/5-simple-ways-to-stay-fit-amp-healthy) [class](https://www.mindstick.com/blog/165/generic-class-in-c-sharp) like:

```
class Color{    public int ID {get; set; }    public string ColorName { get; set; }}
```

and then create a [collection](https://www.mindstick.com/articles/1718/collections-in-java) of these [objects](https://www.mindstick.com/forum/145447/what-are-objects):

List<[Color](https://www.mindstick.com/articles/77/how-to-split-form-background-color-in-c-sharp)> ColorList;

I'd like to then [query](https://www.mindstick.com/blog/202/sub-query-in-sqlserver) this collection with LINQ.

Color selected = ColorList.[SingleOrDefault](https://www.mindstick.com/forum/34064/use-singleordefault-in-linq)(a => a.ID == someVariable);

My collection will have several [colors](https://answers.mindstick.com/qa/31019/should-i-paint-my-interior-with-neutral-or-bright-colors), all with [unique](https://www.mindstick.com/blog/12870/how-to-be-unique-in-business) IDs, and one color that I'd want to be the default. What I'm looking for is the ability to specify what is returned when someVariable does not match any ID in the collection. Is this possible, or does SingleOrDefault only [return null](https://www.mindstick.com/forum/34356/facebook-email-field-return-null-even-if-the-email-permission-is-set-and-accepted) when a match isn't found?

## Replies

### Reply by Pravesh Singh

```
Use ?? (null coalescing operator)Color selected = ColorList.SingleOrDefault(a => a.ID ==someVariable) ??   new Color {Id = 1234, ColorName = "Blue"}; //Default value
```


---

Original Source: https://www.mindstick.com/forum/23023/default-value-when-using-singleordefault

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
