Wrong compiler warning? Or Not?

This piece of code results in a warning. 1: class Test 2: { 3: public static void Main() 4: { 5: object obj = "Senthil"; 6: string myName = "Senthil"; 7: Console.WriteLine(obj == myName); 8: } 9: } The compiler says “warning CS0252: Possible unintended reference comparison; to get a value comparison, cast the left hand side to type ‘string’” on line 7. The compiler is right; it has no way of knowing that obj is actually a string. It infers the static type of obj to be System.Object, and if you’ve done any programming in C# at all, you’ll … Continue reading Wrong compiler warning? Or Not?