11 Replies - 1382 Views - Last Post: 29 July 2011 - 05:42 AM Rate Topic: -----

#1 falcon00  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 56
  • Joined: 23-April 09

Operator '&&' cannot be applied to operands of type de

Posted 28 July 2011 - 04:34 PM

if ((denominator_gap_up = 0) && (denominator_gap_down = 0))


That's a fairly simple line of code. What does that blow up? In the alternative how do the professionals handle the possibility of division by 0?

(sorry for the double post. I can't figure out how to delete the one with the messed up title.)

OMG!! The title is supposed to say decimal!!
Is This A Good Question/Topic? 0
  • +

Replies To: Operator '&&' cannot be applied to operands of type de

#2 AdamSpeight2008  Icon User is offline

  • MrCupOfT
  • member icon


Reputation: 2253
  • View blog
  • Posts: 9,443
  • Joined: 29-May 08

Re: Operator '&&' cannot be applied to operands of type de

Posted 28 July 2011 - 04:38 PM

This a bug bare of mine C# allowing assignment mid-expression.
Change the assignment = to ==
Was This Post Helpful? 1
  • +
  • -

#3 falcon00  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 56
  • Joined: 23-April 09

Re: Operator '&&' cannot be applied to operands of type de

Posted 28 July 2011 - 04:39 PM

Jesus. I would have stared at that all day. Thanks!
Was This Post Helpful? 0
  • +
  • -

#4 Milto  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 23
  • View blog
  • Posts: 139
  • Joined: 10-February 11

Re: Operator '&&' cannot be applied to operands of type de

Posted 28 July 2011 - 07:56 PM

Quick tip, you could just use the Full Editor to change the title when editing a post. :D
Was This Post Helpful? 0
  • +
  • -

#5 Curtis Rutland  Icon User is online

  • (╯□)╯︵ (~ .o.)~
  • member icon


Reputation: 4462
  • View blog
  • Posts: 7,776
  • Joined: 08-June 10

Re: Operator '&&' cannot be applied to operands of type de

Posted 28 July 2011 - 08:33 PM

View PostAdamSpeight2008, on 28 July 2011 - 06:38 PM, said:

This a bug bare of mine C# allowing assignment mid-expression.


It can lead to some very interesting code, but it's far, far less of a problem in C# than it is in C/C++. In those languages, this would actually compile, because bools are actually ints. 0 is false, and anything else is true. In C#, ints are not implicitly converted to bools, so this generates an exception.
Was This Post Helpful? 0
  • +
  • -

#6 macosxnerd101  Icon User is online

  • Self-Trained Economist
  • member icon




Reputation: 10461
  • View blog
  • Posts: 38,771
  • Joined: 27-December 08

Re: Operator '&&' cannot be applied to operands of type de

Posted 28 July 2011 - 08:43 PM

Quote

In the alternative how do the professionals handle the possibility of division by 0?

We take a derivative. ;)
Was This Post Helpful? 1
  • +
  • -

#7 falcon00  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 56
  • Joined: 23-April 09

Re: Operator '&&' cannot be applied to operands of type de

Posted 28 July 2011 - 08:49 PM

That's a joke right?
Was This Post Helpful? 0
  • +
  • -

#8 macosxnerd101  Icon User is online

  • Self-Trained Economist
  • member icon




Reputation: 10461
  • View blog
  • Posts: 38,771
  • Joined: 27-December 08

Re: Operator '&&' cannot be applied to operands of type de

Posted 28 July 2011 - 08:50 PM

Yes- it was a Calculus joke. :)
Was This Post Helpful? 0
  • +
  • -

#9 AdamSpeight2008  Icon User is offline

  • MrCupOfT
  • member icon


Reputation: 2253
  • View blog
  • Posts: 9,443
  • Joined: 29-May 08

Re: Operator '&&' cannot be applied to operands of type de

Posted 28 July 2011 - 10:02 PM

View PostCurtis Rutland, on 29 July 2011 - 04:33 AM, said:

View PostAdamSpeight2008, on 28 July 2011 - 06:38 PM, said:

This a bug bare of mine C# allowing assignment mid-expression.


It can lead to some very interesting code, but it's far, far less of a problem in C# than it is in C/C++.


if ( ConditionExpession ){ onTruthExpession }
else
{ onFalseExpession }

May be so but inside the condition Expression part of an if-statement is just stupid (to me). Any examples where this "feature" is useful.

This post has been edited by AdamSpeight2008: 28 July 2011 - 10:04 PM

Was This Post Helpful? 0
  • +
  • -

#10 Curtis Rutland  Icon User is online

  • (╯□)╯︵ (~ .o.)~
  • member icon


Reputation: 4462
  • View blog
  • Posts: 7,776
  • Joined: 08-June 10

Re: Operator '&&' cannot be applied to operands of type de

Posted 28 July 2011 - 10:21 PM

I can't think of any good ones off the top of my head. I certainly wouldn't recommend using it, since code with side effects is to be avoided when possible. I think the only time I've actually used it was in a code golf competition. I think it's just a holdover from C. The value of an assignment expression is the result of the assignment.
Was This Post Helpful? 0
  • +
  • -

#11 falcon00  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 56
  • Joined: 23-April 09

Re: Operator '&&' cannot be applied to operands of type de

Posted 28 July 2011 - 10:41 PM

Aaaaand you lost me!
Was This Post Helpful? 0
  • +
  • -

#12 Robin19  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 271
  • View blog
  • Posts: 550
  • Joined: 07-July 10

Re: Operator '&&' cannot be applied to operands of type de

Posted 29 July 2011 - 05:42 AM

I came to C# from C++ and Java. Let me try to show an example in C# terms.
gamesWonThisYear = 22;
gamesWonInJuly = 5;

// This is true in other languages.  It is an compile error in C#.
// You can see how this would be hard to debug using your eyes.
if (gamesWonInJuly = gamesWonThisYear)
{
   // First, it would do the assignment.
      //gamesWonInJuly is now equal to 22
   // Second, it would evaluate the int value of the assigned variable
      //gamesWonInJuly is not equal to 0, so it returns true
}

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1