Shall we consider adding more unary and binary operator functionalities? #8367
-
I hope for the addition of more unary and binary operator functionalities, allowing for more concise and expressive syntax in C#. For example, the current if (bCondition)
{
someVar = "Hello";
} This can be slightly simplified: if (bCondition)
someVar = "Hello"; However, I propose supporting a syntax like the following: bool bCondition = true;
object obj = null;
bCondition ?? someVar = "Hello";
obj ?? bCondition = false;
(!bCondition) ?? someVar = "No"; This would enable more streamlined and readable code, reducing the need for verbose conditional statements. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
At best it seems that you're only saving two characters over the current syntax of: // proposed
bCondition ?? someVar = "Hello";
// already legal
if (bCondition) someVar = "Hello"; |
Beta Was this translation helpful? Give feedback.
-
I support adding more optional symbols as operators. Anyway, they are essentially just shorthand for calling methods. |
Beta Was this translation helpful? Give feedback.
At best it seems that you're only saving two characters over the current syntax of: