[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 359
  • Last Modified:

Extending two classes in c#

I have two classes A, B

class A
{
    member of A;
}

class B
{
    member of B;
}


I want a class of type B.
But I need the members of A also in that class.
But in c# we cant extend Both A and  B classes.
Is there any way to Get Class A members in my new class.?

other wise i have to duplicate the members and functions of Class A.

Please help me....
0
Ashok9
Asked:
Ashok9
  • 9
  • 6
9 Solutions
 
zadeveloperCommented:
Make class a abstract and then inherit from it.
class A : B
{
    member of A;
}

abstract class B
{
    member of B;
}

Open in new window

0
 
zadeveloperCommented:
class B now also has member of A
0
 
Ashok9Author Commented:
Here the big trouble I am facing is I cant touch both the classes A and B.  Sorry I forgot to mention.
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
zadeveloperCommented:
Explain what you mean by: you cant touch the classes? - can you add methods and properties ?
0
 
Ashok9Author Commented:
Those two classes A, B are the framework classes which I am using. I am not supposed to touch any of them.
0
 
zadeveloperCommented:
what type of classes are they ? (which classes ?)
0
 
Ashok9Author Commented:
Its our internal framework. Both are controls basically.
0
 
zadeveloperCommented:
can you create a third class and inherit from both of them ?
0
 
Ashok9Author Commented:
Yes. I can create any number of classes. But In my new class how do I inherit both of them?
0
 
zadeveloperCommented:
Without touching class A or B it is not possible to get the objects from 1 class into another.
0
 
zadeveloperCommented:
if they are not concrete classes (They should be Abstract) then you could do something like:
class C : A, B

Open in new window

0
 
Ashok9Author Commented:
Unexpectedly I cant. because they are not abstract.
0
 
zadeveloperCommented:
Unfortunatly because the classes are not inheritable and you cannot modify them you will not be able to access members of class A from B, as they dont know about each other. What you could possibly look at in the future is creating a new class and using the dynamic properties. (This should not be done lightly as it has pros and cons), also it will only be available in framework 4 which is still in Beta.
Sorry man,
Happy coding.
0
 
zadeveloperCommented:
Hey

please could you resolve this issue. Did you manage to come right?
0
 
Ashok9Author Commented:
Thanks for your help
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

  • 9
  • 6
Tackle projects and never again get stuck behind a technical roadblock.
Join Now