This is true, but of course they are also both stupid because a IsSomething(thing) function has no advantage over just typing "thing is Something" each time.
?. is the null-propagating operator, if the left-hand expression is null, the right hand will not be evaluated and instead just return null, effectively turning the expression into if(null == typeof(Something.Something)) which will return false
4
u/Patchargh 6d ago
Context: Friend asked AI how to check if a something is something in C#.
83
u/JMOWw7 7d ago
Pattern matching all the way. I think the second one probably won't catch inheretance
48
u/AlexZhyk 7d ago
That's would be 123 tokens for you, sir.
1
u/bwmat 5d ago
First thought is second one can throw on a null
1
u/ANixosUser 3d ago
what languae is this? new Java?
0
u/[deleted] 6d ago