Ricardo Rocha
Ricardo Rocha

Reputation: 16266

Get parent class using the child

I have two classes which one is the generalization of the other:

public class son: parent { ... }

Then, I have a function that receives an generic object, which their type is son:

public void func(object son) {...}

What I want, is a way to extract the parent part from the object son

Upvotes: 0

Views: 101

Answers (1)

user8719628
user8719628

Reputation:

You can specify what kind of object is son and then extract Parent by casting it such as this:

public void func(T son) where T: Parent
{...}

Here object son is of type Parent and you can extract the relevant information you need.

Upvotes: 1

Related Questions