How do a turn this
public static List<T> CreateListOfAnonymous<T>(T unused) {return new List<T>();}
into a lamda. I just can’t seem to work it out. as a generic of a generic gives an error
i.e:
Func<T,T> ..... fails because its looking for a real type.
My goal is to use the logic from that method above, but without a method, just internally inside some method.
If the method or type you’re using the lambda in is generic (so that you have a type that is concrete in-context) then you can get this to work:
If neither is true for your code, or you want to keep
Tfor the lambda as an open generic (potentially of some other type than the method or class’s generic parameters), then it won’t be possible, as leppie mentioned.I’ve found in cases where I’ve wanted to do this type of thing in the past (to avoid repeating myself), I only had a few types I wanted to bind to in the method. So I just bit the bullet and created one concrete version for each type I wanted to support: