IEnumerableExtensionFirstOrNullTSource(IEnumerableTSource, FuncTSource, Boolean, Boolean) Method

Gets the first VCardProperty from a collection of VCardProperty objects and allows filtering of the items, and to specify whether or not to ignore empty items.

Definition

Namespace: FolkerKinzel.VCards.Extensions
Assembly: FolkerKinzel.VCards (in FolkerKinzel.VCards.dll) Version: 8.0.1+a91cc3f0fd39aeb548e16006a60ca9dd10a304a2
C#
public static TSource FirstOrNull<TSource>(
	this IEnumerable<TSource>? values,
	Func<TSource, bool>? filter,
	bool skipEmptyItems = true
)
where TSource : VCardProperty

Parameters

values  IEnumerableTSource
The IEnumerableT of VCardProperty objects to search. The collection may be null, empty, or may contain null references.
filter  FuncTSource, Boolean
A FuncT, TResult which allows additional filtering of the items, or null to not perform additional filtering. The arguments of the delegate are guaranteed to not be null.
skipEmptyItems  Boolean  (Optional)
Pass false to include empty items in the return value. ("Empty" means that IsEmpty returns true.) null values will always be ignored.

Type Parameters

TSource
Generic type parameter that's constrained to be a class that's derived from VCardProperty.

Return Value

TSource

The first VCardProperty from values that passes the filter, or null if no such item could be found. This happens in any case

  • if values is null,
  • if values is empty,
  • if values contains only null references,
  • or if values contains only empty items and skipEmptyItems is true.

"First" is defined as the item with the lowest Index value. If Index is null, MaxValue is assumed.

If no Index is specified, the first VCardProperty that passes the filter is returned.

Usage Note

In Visual Basic and C#, you can call this method as an instance method on any object of type IEnumerableTSource. When you use instance method syntax to call this method, omit the first parameter. For more information, see Extension Methods (Visual Basic) or Extension Methods (C# Programming Guide).

See Also