Why can I not assign a delegate or lambda to a C# 15+ union type?
I have the following union (C# 15+): public union ValueSource(int, Func<int>); As per the docs: An implicit union conversion exists from each case type to the union type So I expect both of the following to work: ValueSource src1 = 42; ValueSource src2 = () => 42; However, the assignment to src2 fails with: CS1660: Cannot convert lambda expression to type 'ValueSource' because it is not a delegate type Moreover, if I have this static method: public class IntSource { public static int Get() => 42; } The following assignment also fails: ValueSource src3 = IntSource.Get; with: CS0428: Cannot conv
0 upvotes
View original discussion ↗
Comments
Sign in or sign up to comment and upvote.
No comments yet.