https://github.com/jpmikkers/baksteen.extensions.wherenotnull
Extension methods to skip null elements from a sequence
https://github.com/jpmikkers/baksteen.extensions.wherenotnull
csharp extension extension-method nullable
Last synced: 20 days ago
JSON representation
Extension methods to skip null elements from a sequence
- Host: GitHub
- URL: https://github.com/jpmikkers/baksteen.extensions.wherenotnull
- Owner: jpmikkers
- License: mit
- Created: 2022-03-20T15:28:25.000Z (about 3 years ago)
- Default Branch: main
- Last Pushed: 2025-02-20T10:16:18.000Z (3 months ago)
- Last Synced: 2025-05-02T07:50:21.773Z (22 days ago)
- Topics: csharp, extension, extension-method, nullable
- Language: C#
- Homepage:
- Size: 11.7 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Baksteen.Extensions.WhereNotNull
This package contains a pair of IEnumerable extension methods named `WhereNotNull()`. The method skips all null elements from a sequence.
This is useful for projects that have nullable reference types enabled because it converts `IEnumerable` into `IEnumerable` .
## How to use:
For nullable reference types:
using Baksteen.Extensions.WhereNotNull;
...
var seq = new string?[] { "one", null, "two", null, null, "three", null, null, null }
var result = seq.WhereNotNull();
// the result is IEnumerable { "one", "two", "three" }
For nullable value types:
using Baksteen.Extensions.WhereNotNull;
...
var seq = new int?[] { 1, null, 2, null, null, 3, null, null, null }
var result = seq.WhereNotNull();
// the result is IEnumerable { 1, 2, 3 }## See also
For more insight on the rationale of this extension, see:
* https://github.com/dotnet/runtime/issues/30381
* https://stackoverflow.com/questions/59431558/using-linqs-where-select-to-filter-out-null-and-convert-the-type-to-non-nullabl