All too often I find myself writing if clauses with negative logic - rather than checking for a true condition, I check for false:
if (!myDictionary.Contains(key))
{ }
This syntax, while very common, isn't really easy to parse. While I can express my required logic in words as "if my dictionary does not contain key", my syntax reads like the unintuitive "if not my dictionary does contains key" - I tend to think of my C# code in terms of natural languages. Usually English, even though it's not my native tongue.
So in order to bring C# more in line with my way of thought, I thought of having C# accept this sort of syntax:
if (myDictionary.!Contains(key))
{ }
The .! operator is valid only before a boolean member, and inverts the return value, making it equivalent to the code above. Now the code reads the way it should and is just as easy to understand.
How does this sound? Any other supporters for this? Should I file a feature request on Connect?
(Originally posted on my blog, but I wanted Niner opinions too)
Thread Closed
This thread is kinda stale and has been closed but if you'd like to continue the conversation, please create a new thread in our Forums,
or Contact Us and let us know.