qwertie / ecsharp

Home of LoycCore, the LES language of Loyc trees, the Enhanced C# parser, the LeMP macro preprocessor, and the LLLPG parser generator.
http://ecsharp.net
Other
172 stars 25 forks source link

EC#: Syntax error in `Foo<T?>` #133

Open qwertie opened 3 years ago

qwertie commented 3 years ago

This gives a syntax error:

public static IEnumerable<T> WhereNotNull<T>(this IEnumerable<T?> list) where T : struct
{
    foreach (var item in list)
        if (item != null)
            yield return item.Value;
}

There are a couple of workarounds - you can use Nullable<T>, or this alternate syntax:

public static IEnumerable<T> WhereNotNull<T>(this IEnumerable<@`'?`<T>> list) where T : struct