Results 1 to 4 of 4

Thread: [2.0] is operator not being able use

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Oct 2003
    Posts
    436

    [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");

    }

  2. #2
    Fanatic Member
    Join Date
    May 2001
    Posts
    837

    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)) ...
    The human brain cannot hold all of the knowledge that exists in this world, but it can hold pointers to that knowledge.

  3. #3
    Addicted Member MasterBlaster's Avatar
    Join Date
    Jul 2002
    Location
    Seattle
    Posts
    196

    Re: [2.0] is operator not being able use

    Code:
    if(objA.Equals(objB))
    "And most of the evils of society can, in fact, be cured through information. We have a society that has been disinformed and based on the disinformation has made irrational choices. And that's what I mean by 'ignorance.' People, who ordinarily might be smart, are deprived of the data by which to make a rational decision, don't have the data to do it."
    Frank Zappa

  4. #4
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    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 '=='.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width