ExtensionMethod.NET Home of 876 C#, Visual Basic, F# and Javascript extension methods


Returns the object if it's not null or the first object which is not null.


public static T Or<T>(this T t, params T[] args)
    foreach (var item in args)
        if (item != null) return item;
    return default(T);


string s = GetValue(); // s == null
Console.WriteLine(s.Or("value not found")):

Author: Weidling C

Submitted on: 7 dec 2009

Language: C#

Type: System.Object<T>

Views: 3635