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 6110185
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T14:29:13+00:00 2026-05-23T14:29:13+00:00

I have an object (A) with many properties. I make a new object B

  • 0

I have an object (A) with many properties. I make a new object B that extends the object A with some new properties.

Then I have an method AA that returns the instance of object A, but in my current method BB I use the new instance of object B.

Do I have any way to use the return of the method AA to assign in the object B?, How do I assign to B avoiding copy property by property?

class A
{
   string a1 {get; set;}
   // ...
   string a50 {get; set;}
}

class B: A
{
   string bState {get; set;}
   string bMessage {get; set;}
}

class ObjAA
{
   public static AA ReturnAA() 
   {
       AA oAA = new AA();
       //... 
       return oAA;
   }
}

class ObjBB
{
   public void UseBB() 
   {
       BB oBB = new BB();

       var aa = ObjAA.ReturnAA();

       // How do I assign to B avoiding property by property?
   }
}

thanks

  • 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-05-23T14:29:14+00:00Added an answer on May 23, 2026 at 2:29 pm

    Marc Gravell mentions one way, which is fine.

    Another is to just have the method return an instance of B for you. How? Use generics.

    class ObjAA {
        public static T ReturnA<T>() where T : A, new() {
            T oAA = new T();
            // fill the properties of A
            return oAA;
        }
    }
    

    Then:

    class ObjBB
    {
       public void UseBB() 
       {
           var bb = ObjAA.ReturnA<B>();
           // bb is a B, and the properties it inherits from A are filled
       }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a data object that has many different List properties. I want to
I have an object in SQL (A) that has a many to many relationships
I want to make a sort in Java. In my object I have many
I have a property on a domain object that is declared in a many-to-one
I have an Activity object with many properties. One of them is as follows:
I have two object : Mother and Child. Mother have many Children, How can
I have a JPA object which has a many-to-many relationship like this: @Entity public
I have a parent object which has a one to many relationship with an
I have a base class object array into which I have typecasted many different
Many languages have a facility to check to see if an Object is of

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.