Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does >= work but => not?

Tags:

operators

c#

When checking if a integer is the same or above a current number.. so I type

if (5 => 6) { //Bla } 

but it shows this as a error. Why? Isn't it exactly the same as

if (5 >= 6) { //Bla } 
like image 722
Theun Arbeider Avatar asked Nov 27 '22 22:11

Theun Arbeider


2 Answers

The reason why it does not work is because => is not equivalent to >=.

=> is used in a lambda expression. Like :

(int x, string s) => s.Length > x

I do agree it is annoying. Before lambda expressions I used to get it wrong sometimes. Now I always know that one (=>) is a lambda expression and and other (>=) is the greater than equal to sign

like image 81
gideon Avatar answered Nov 29 '22 13:11

gideon


Because the operator is >= not =>.

The writers of the language could have chosen either syntax, but had to choose one. Having two operators meaning the same thing would be confusing at best.

However, the operator is read "greater than or equal to" so it does make sense that the > symbol is first.

Also => is now used for Lambda expressions.

like image 23
ChrisF Avatar answered Nov 29 '22 11:11

ChrisF