-1

I got this code which was written in C++:

static double e[66];
if (!e[0]) {
   // Do Something
}

It does not compile in Visual Studio saying that Operator '!' cannot be applied to operand of type 'double'.

What is the propar way to write it in C#?

CodeMonkey
  • 11,196
  • 30
  • 112
  • 203
Elizabeth Dimova
  • 255
  • 1
  • 3
  • 19
  • What should `!`applied to a ``double` value actually mean? Equal to `0.0`?? – πάντα ῥεῖ May 31 '15 at 10:57
  • 1
    ! is for bools not doubles,explain what you want to do – Milad Qasemi May 31 '15 at 10:59
  • See http://stackoverflow.com/questions/9833790/what-happens-when-you-logical-not-a-float, same is valid for double – deviantfan May 31 '15 at 11:03
  • In c, zero would be false and anything else would be true. So the equivalent in c# would be if(e[0] != 0) – jdweng May 31 '15 at 11:03
  • Why you guys downvote my question and then ask obliviously sillier questions? Anyway for those not so frustrated; i don't know what this if statement is supposed to check. Actually i am about to find out if i convert the code. Thank you – Elizabeth Dimova May 31 '15 at 11:05
  • Why you post code-translation request instead of a question? And why are you "translating" code when you don't apparently know either source **or** destination language? – Blorgbeard May 31 '15 at 11:10
  • change it to `static double e[66]; if(e[0] != 0) { // Do Something }` – Milad Qasemi May 31 '15 at 11:14
  • I said for the non-frustrated people willing to help. Guys like you that do not want to help indeed could just downvote and feel happy because of that. Anyway i believe that jdweng's suggestion is what i am looking for. Thank you and sorry for not being able to vote for your solution. Cheers – Elizabeth Dimova May 31 '15 at 11:16
  • don't worry, I gave you a thump up and supplied an answer – CodeMonkey May 31 '15 at 11:25
  • Thank you so much Yonatan. It's much appreciated. – Elizabeth Dimova May 31 '15 at 11:43

1 Answers1

1

C# does not consider boolean as an int/double that can be used as a true/false statement.

You will have to write something like:

if(e[0] == 0.0) ..

Also, you can't have a local static variable like in C++. You can declare it as a class member, initialize it in the static constructor and then use it.

CodeMonkey
  • 11,196
  • 30
  • 112
  • 203