[2.0] is operator not being able use
I am trying to use "is" operator and I am getting some compiler error:
The type or namespace name 'xxxStuntPilot' could not be found (are you missing a using directive or an assembly reference?)
code:
class Program
{
static void Main(string[] args)
{
Pilot basamPilot = new Pilot();
StuntPilot xxxStuntPilot = new StuntPilot("Danny");
xxxStuntPilot.HowmanyHoursofFlying(5);
Pilot yyyPilot = xxxStuntPilot;
if (yyyPilot is xxxStuntPilot)
{
Console.WriteLine("They are same");
}
else
{
Console.WriteLine("They are not same");
}
Re: [2.0] is operator not being able use
The is operator works with a variable and a type, not two variables. See http://msdn.microsoft.com/library/de.../vclrfispg.asp
I think your if statement should look like this: if (yyyPilot is typeof(xxxStuntPilot)) ...
Re: [2.0] is operator not being able use
Code:
if(objA.Equals(objB))
:confused:
Re: [2.0] is operator not being able use
The 'Is' keyword works like that in VB but the C# 'is' keyword is not the same, as stated previously. You can simply use the '==' operator. In VB you test value equality with '=' and reference equality with 'Is'. In C# you test them both with '=='.