Add a new C# operator "in" to check if an item is in the data structure. #2635
Replies: 8 comments
-
So, where would this be used? Is it essentially an alias for a |
Beta Was this translation helpful? Give feedback.
-
Duplicate of #1665. |
Beta Was this translation helpful? Give feedback.
-
@Tom01098 We could however also use it with reflection to check if a property with a given name exists in an object, or class. Just like |
Beta Was this translation helpful? Give feedback.
-
@mckabue reflection is something that should not be this convenient to use. It bypasses a lot of the safeguards built into C# and is much slower than regular programming. Its syntax is all "I understand the risks and want to proceed" by design. |
Beta Was this translation helpful? Give feedback.
-
@mckabue This would definitely never be implemented with reflection as it bypasses type safety. If it's just an alias for |
Beta Was this translation helpful? Give feedback.
-
@Tom01098 I have nothing against |
Beta Was this translation helpful? Give feedback.
-
But why? if (1 in someArr) if (someArr.Contains(1)) It doesn't add much, it is just some syntactic sugar which is kinda ... useless. Why make an alternative for no reason? A proposal needs to be valuable to be accepted into the lang |
Beta Was this translation helpful? Give feedback.
-
They're moving from a quite different language, C# isn't python v2 :) Adding new ways of doing the same thing means people will have to learn both when reading and maintaining code, making it harder to do both. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
dotnet/roslyn#37037 (comment)
Beta Was this translation helpful? Give feedback.
All reactions