Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7879573
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T03:55:35+00:00 2026-06-03T03:55:35+00:00

I have a set of Class A and Class B both have Some properties.

  • 0

I have a set of Class A and Class B both have Some properties. and another Class C which has their own properties.

Whenever i create a instance of class C i want to access all properties of all three classes with objClassC.

How can i Achieve this in C#?

I m facing two problem :-

  1. I can not inherit both the classes A, B in Class C (C# doesn’t Support Multiple Inheritance)
  2. if i use Interface instead of Class A, B (In Interface we can not Contains Fields)
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T03:55:36+00:00Added an answer on June 3, 2026 at 3:55 am

    Why don’t you contain instance of Class A and Class B inside Class C. Use Composition

    class C
    {
    //class C properties
    public A objA{get;set;}
    public B objeB{get;set;}
    }
    

    Then you can access

    C objc = new C();
    objc.objA.Property1 = "something";
    objc.objB.Property1 = "something from b";
    

    check out the article Composition vs Inheritance

    EDIT:

    if i use Interface instead of Class A, B (In Interface we can not
    Contains Fields)

    Well, interfaces can’t contain fields, if you define one, you will get compilation error. But interfaces can contain properties with the exception that you can’t specify the access specifiers, as all elements of the interface are considered public. You can define properties for Interface ‘A’ and ‘B’ as:

    public interface IA
    {
         int Property1 { get; set; }
    }
    
    
    public interface IB
    {
        int Property2 { get; set; }
    }
    

    Then you can implement them in the class C like:

    public class C : IA, IB
    {
        public int Property1 { get; set; }
        public int Property2 { get; set; }
    }
    

    Later you can use them as:

    C objC = new C();
    objC.Property1 = 0;
    objC.Property1 = 0;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a customer class which has both PhoneNumber and Email properties. Using DataAnnotations
I have a class that is inherited from List<T> and also has some properties,
I have public class ViewModel1 { // some properties here public List<ViewModel2> ViewModel2 {get;
I have a JSF ManagedBean which has a property that should be set by
I`m trying to display classes that have properties of type some custom class inside
I have set up the following: Database class ($db) Pagination class ($paginator) I am
I have set an onPreferenceClickListener on my subclass of DialogPreference like so: public class
In C#, I have a class set up like so: class Page { public
I have something like this set up: class CategoryPage (webapp.RequestHandler): def get(self): ** DO
I have the following models set up: class Contact < ActiveRecord::Base belongs_to :band belongs_to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.