Jump to content

How to tell if a part is a compoundpart


Recommended Posts

I need to know as I run through a list of parts on a vessel, which ones are compound parts.

CompoundParts inherit from Part, 

I'm going through the list of parts on a vessel using:

foreach (Part p in parts)
                    {

How can I tell if p is a CompoundPart or not?

Thanks

Link to comment
Share on other sites

if (p is CompountPart) // true if it is the derived type
{
	CompoundPart cp = (CompoundPart)p; // exception on fail
	//
}

// or
CompoundPart cp = p as CompoundPart; // as cast returns null when it fails
if (cp != null)
{
	//
}

 

Link to comment
Share on other sites

This thread is quite old. Please consider starting a new thread rather than reviving this one.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...