Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Parentheses or just Quotes?

Okay, so I've known about this for like 600 years now, but I've only just now cared to wonder why.

Why, in C# can we assign to a string like this?:

string f = "u";

AND ALSO:

string n = ("ny");

Is there any difference? I've not noticed any, but I always use ""; without the parentheses.

like image 479
βӔḺṪẶⱫŌŔ Avatar asked Mar 03 '26 05:03

βӔḺṪẶⱫŌŔ


1 Answers

There is not any difference. The parenthesis can be used in any expression to explicitly define precedence of the operations. For your simple case, the expression is the string itself, so there is no need for the parenthesis. There is no difference in the compiled IL.

like image 112
driis Avatar answered Mar 04 '26 19:03

driis



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!