+ 6
Is there an === evaluation?
in some other languages the === operant checks for same value AND variable type. so 4.0 == 4 may be true but 4.0 === 4 would be false since one is a float and the other is an integer.
5 Antworten
+ 6
As you already noticed c# doesn't have this operator. but there are ways to do this
var assignable = (4.0).GetType().IsAssignableFrom(4.GetType()); // true
This returns true that means you can assign int to double. if you exchange 4 with 4.0 it returns false.
var assignable = 4.GetType().IsAssignableFrom((4.0).GetType()); // false
you can also check if types are exactly equals by doing
if(4.GetType() == 4d.GetType())
here int is not same as double so if block does not get executed.
+ 2
I don't think there's a === in c#.
+ 1
55%5=5.0 | 5.0 get type.true === 5. get type. false
0
As you already noticed c# doesn't have this operator. but there are ways to do this
var assignable = (4.0).GetType().IsAssignableFrom(4.GetType()); // true
This returns true that means you can assign int to double. if you exchange 4 with 4.0 it returns false.
var assignable = 4.GetType().IsAssignableFrom((4.0).GetType()); // false
you can also check if types are exactly equals by doing
if(4.GetType() == 4d.GetType())
here int is not same as double so if block does not get executed.