Is Descendent

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Marco Rego

    #1

    Is Descendent

    How do I know if a class is descendent of another one,
    not necessaraly his direct parent ?
    In my case, I need to know if a certain class descends
    from Control.
    Thanks for any help.

    _____
    Marco
  • Juan Gabriel Del Cid

    #2
    Re: Is Descendent

    Just use the "is" operator, like so:

    if (myObject is Control) {
    // myObject is a Control
    }

    Hope that helps,
    -JG


    Comment

    • Jon Skeet [C# MVP]

      #3
      Re: Is Descendent

      Juan Gabriel Del Cid <jdelcid@atrevi do.nospam.net> wrote:[color=blue]
      > Just use the "is" operator, like so:
      >
      > if (myObject is Control) {
      > // myObject is a Control
      > }[/color]

      That works for an *instance* of a type. If Marco needs to know the
      information just from the type itself, he could use:

      if (typeof(Control ).IsAssignableF rom (testType))
      {
      ....
      }

      --
      Jon Skeet - <skeet@pobox.co m>
      Pobox has been discontinued as a separate service, and all existing customers moved to the Fastmail platform.

      If replying to the group, please do not mail me too

      Comment

      • Marco Rego

        #4
        Re: Is Descendent

        Thanks Jon and Juan. I will need both ways.

        ______
        Marco

        Comment

        Working...