Are there any languages where "A == B == C" works where A, B, and C are all non-boolean types? -
without thinking in c# tried compare 3 objects. failed, , explained why [since (typeof("a == b") == bool) , (typeof(c) != bool) invalid comparison]. languages support short circuiting logic this?
there several languages let multiple conditionals this. first think of python
example:
a = 5 b = 5 c = 5 if(a == b == c): print "yes" else: print "no"
will print "yes" in console.
it works other types well, this:
a = ["a",1] b = ["a",1] c = ["a",1] d = ["a",1] if(a == b == c == d): print "yes" else: print "no"
now reason c# (and other c languages) doesn't support evaluate comparison expressions down true / false, compiler sees when (5 == 5 == 5) ((5 == 5) == 5) yields: (true == 5) invalid since cannot compare boolean integer, write (a == b == c) if c boolean, (5 == 5 == true) work.
Comments
Post a Comment