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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T04:17:00+00:00 2026-05-26T04:17:00+00:00

In C# 4.0 (or earlier if it can be done), how does a parent

  • 0

In C# 4.0 (or earlier if it can be done), how does a parent class pass a reference of itself to a child class. For example:

class Book
{

    public string bookname = "a";
    public static List<Page> pages = new List<Page>();

    static void Main(string[] args)
    {
        Page pageone = new Page("one");
        pages.Add(new Page("one"));
    }
}
public class Page
{
    Book book;
    public Page(string pagetitle)
    {
        Console.WriteLine(pagetitle);
        Console.WriteLine("I'm from bookname :?");
    }
}

How can I get Page to recognize which book it’s in? I’m trying to pass the Book class in the constructor, but don’t know how.

  • 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-26T04:17:01+00:00Added an answer on May 26, 2026 at 4:17 am

    You’re having trouble because you’ve made your book class the entry point for your application, which means you don’t have an actual Book instance.

    Try something like this instead:

    public class Program
    {
        static void Main(string[] args)
        {
            Book book1 = new Book();
            book1.AddPage("one");   
        }
    }
    
    public class Book
    {
        public string Bookname = "a";
        public List<Page> Pages = new List<Page>();
    
        public void AddPage(string pageTitle)
        {
            Pages.Add(new Page(this, pageTitle));
        }
    }
    
    public class Page
    {
        Book book;
        public Page(Book b, string pagetitle)
        {
            book = b;
            Console.WriteLine(pagetitle);
            Console.WriteLine("I'm from book '{0}'.", book.Bookname);
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I came across a strange behaviour with Chrome earlier that I can't seem to
I asked a question earlier about why left joins in Linq can't use defined
I see that date comparisons can be done and there's also datetime.timedelta() , but
I'm in a basic programming class, and everything is done in pseudo code. My
I have done a lot of research and I can't work out if this
Earlier this week, I had to do something which feels like a semantics violation.
Earlier I encountered a problem with dynamic memory in C (visual studio) . I
Earlier to deploy my dot-net project into my remote server I was using copy
Earlier today I asked similar problem to find the maximum element which is common
Earlier I asked how to fire an event when a TreeNode was renamed (

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.