lucenenet-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From GitBox <...@apache.org>
Subject [GitHub] [lucenenet] NightOwl888 commented on pull request #345: Reduce casting
Date Tue, 22 Sep 2020 16:47:53 GMT

NightOwl888 commented on pull request #345:
URL: https://github.com/apache/lucenenet/pull/345#issuecomment-696844345


   Interesting. I suspect they wouldn't produce the same IL if the type in the comparison
had the `!=` operator overloaded - then it may produce very different results, and in fact
depending on the implementation it might not produce expected results. `is` is safer because
it doesn't take the operator overloads into account.
   
   That said, I am on board with elad in that using `== object` is not very intuitive for
a `null` check. I prefer:
   
   ```c#
       public static void A(IMyInterface c) {
           if(!(c is null) && c is MyClass cc) {
               Console.WriteLine(cc.GetType());
           }
       }
   ```
   


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



Mime
View raw message