Equals Operator

  • Thread starter Thread starter Roger
  • Start date Start date
R

Roger

What did MS not take the chance to change
the silly == operator when they designed C#,
to something reasonable like = ?
Why change the universal meaning of = ?

Wouldn't it be better to have:
Assignment := //or something else
Equal = //but keep = to be =

My view,
Roger
 
Roger said:
What did MS not take the chance to change
the silly == operator when they designed C#,
to something reasonable like = ?
Why change the universal meaning of = ?

Wouldn't it be better to have:
Assignment := //or something else
Equal = //but keep = to be =

Because it's not the universal meaning of =. In particular, that's not
the meaning of = in C, C++ or Java, which is what the syntax of C# is
based on.
 
Roger:

The language is called C#. Much of the syntax is taken from C/C++ design. I
lot of the problems that were caused by == in C / C++ are caught be the C#
compiler. You can't get away with stuff like:

if (a = b)

In most cases this is a typo in C / C++ but the comiler wouldn't flag it. If
was zero it would come out false else it would be true. C# will yell at
you if you try this.

Problem solved.
 
Roger said:
What did MS not take the chance to change
the silly == operator when they designed C#,
to something reasonable like = ?
Why change the universal meaning of = ?

Wouldn't it be better to have:
Assignment := //or something else
Equal = //but keep = to be =

My view,
Roger

I also think pascal style makes more sense.

As I'm used to Delphi I typically assign when I should compare, which makes
for some funny bugs when I have (the misfortune) to code in C/C++. My Bad.

But as C# protects you from doing stupid things with assignments, it's no
big deal.
And as I do 99% of my coding in C# nowadays, I seldom make these kind of
mistakas anymore.

- Michael S
 
Back
Top