CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Apr 1999
    Location
    Galway, Ireland
    Posts
    96

    Simple typeof question

    Is there a better way to do this, where C:B:A:

    Code:
    if (X.GetType().IsSubclassOf(typeof(A)) ||
        X.GetType() == typeof(A))
    {
         A bob = (A)X;
    }
    The problem with IsSubclassOf() is that if the type is A, it returns false.
    Lounge One-Eleven Presents: Gong! v2.0 - you never knew you needed it until you lived without it

  2. #2
    Join Date
    Mar 2004
    Location
    33°11'18.10"N 96°45'20.28"W
    Posts
    1,808

    Re: Simple typeof question

    Code:
    if(X is A) { ... }

  3. #3
    Join Date
    Apr 1999
    Location
    Galway, Ireland
    Posts
    96

    Re: Simple typeof question

    Can't get much more simple than that. Cheers!
    Lounge One-Eleven Presents: Gong! v2.0 - you never knew you needed it until you lived without it

  4. #4
    Join Date
    Feb 2005
    Location
    Israel
    Posts
    1,475

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

Featured