Compilor error, run no error

hi all, following is my code

//----------------------------------------------------------------------------------------------------
class Example3_9{
      public static void Main(){
            
            int myInt = 0;
                bool compatible = myInt is int;
            System.Console.WriteLine("myInt is int: "+compatible);
                System.Console.ReadLine();
      }
}
//----------------------------------------------------------------------------------------------------

it compiled with error, yet being able to run successfully. The error message i got was the following

Example3_9.cs(5,35): warning CS0183:
The given expression is always of the provides ('int') type
eturfclubAsked:
Who is Participating?
 
YurichConnect With a Mentor Commented:
it's not an error, it's just warning.
And what it's saying, "The given expression is always of the provided ('int') type", means that you set myInt as int:

int myInt = 0;

and regardless of how many times you check its type:

bool compatible = myInt is int;

myInt will be alway int.


Just to give a contrary example

foreach( Control c in this.Controls )
   if( c is Button )
      (( Button )c ).BackColor = Color.Red;

in this case c can be anything including Button

regards
0
 
eturfclubAuthor Commented:
thanks
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.