Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"if (object is (string, Color))" c# 7.0 tuple usage doesn't work

I'm using Visual Studio 2017 RC and I have installed the System.ValueTuple package which enables the new c# 7.0 tuple usage, but I can't make it work in this specific case:

As you can see, the first method doesn't have any red squigglies and it just works. But trying to do o is (string, Color) fails with unrelated errors:

Can the new tuples not be used in this way? Or is it just the current state of the package? I have updated it to the latest version btw, which is 4.3.0 at this time. I've read this MSDN post but didn't find any such usage.

like image 806
user1306322 Avatar asked Nov 27 '16 18:11

user1306322


1 Answers

Roslyn contains tests that ensure using tuples in pattern matching does cause errors (added in this PR, which does not explain anything), so it seems this is currently the expected behavior. I'm not sure what is the reason for that, or if the final version of C# 7.0 is planned to behave like this. It certainly is something that I would expect to work.

like image 121
svick Avatar answered Oct 20 '22 00:10

svick