+ 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.

31st Jan 2017, 11:58 PM
Culain
Culain - avatar
5 Réponses
+ 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.
1st Feb 2017, 12:03 AM
M.kazem Akhgary
M.kazem Akhgary - avatar
+ 2
I don't think there's a === in c#.
1st Mar 2017, 12:26 AM
Dheshoju Kalyan Kumar
Dheshoju Kalyan Kumar - avatar
+ 1
55%5=5.0 | 5.0 get type.true === 5. get type. false
4th Feb 2017, 5:46 AM
HACKER
HACKER - avatar
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.
18th Feb 2017, 12:04 PM
divyanshu verma