-
I think VB has something like this:
This way you can constrain a variable to multiple types at once without having to actually create a class implementing all those types. This is really nice when dealing with third party libraries to which you don't have the source code! Would be nice to have the same feature in C#:
|
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 1 reply
-
Can you give an example of what you mean in VB? Your code doesn't seem to parse. |
Beta Was this translation helpful? Give feedback.
-
VB.NET doesn't have union types or intersection types. There is an existing proposal to explore them in C#, but without runtime support they would likely not work very well: #399 |
Beta Was this translation helpful? Give feedback.
-
You must be thinking of generic constraints, which do have a syntax like that: Public Class C
Public Sub M(Of T As { IDisposable, IComparable })(ByVal o As T)
End Sub
End Class That's a very different thing, and C# already supports that with different syntax: public class C {
public void M<T>(T o) where T : IDisposable, IComparable { }
} |
Beta Was this translation helpful? Give feedback.
You must be thinking of generic constraints, which do have a syntax like that:
That's a very different thing, and C# already supports that with different syntax: