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

  • Home
  • SEARCH
  • 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 778591
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T19:47:18+00:00 2026-05-14T19:47:18+00:00

Background: I have enclosed (parent) class E with nested class N with several instances

  • 0

Background: I have enclosed (parent) class E with nested class N with several instances of N in E. In the enclosed (parent) class I am doing some calculations and I am setting the values for each instance of nested class. Something like this:

n1.field1 = ...;
n1.field2 = ...;
n1.field3 = ...;
n2.field1 = ...;
...

It is one big eval method (in parent class). My intention is — since all calculations are in parent class (they cannot be done per nested instance because it would make code more complicated) — make the setters only available to parent class and getters public.

And now there is a problem:

  • when I make the setters private, parent class cannot acces them
  • when I make them public, everybody can change the values
  • and C# does not have friend concept
  • I cannot pass values in constructor because lazy evaluation mechanism is used (so the instances have to be created when referencing them — I create all objects and the calculation is triggered on demand)

I am stuck — how to do this (limit access up to parent class, no more, no less)?


I suspect I’ll get answer-question first — “but why you don’t split the evaluation per each field” — so I answer this by example: how do you calculate min and max value of a collection? In a fast way? The answer is — in one pass. This is why I have one eval function which does calculations and sets all fields at once.

  • 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-14T19:47:19+00:00Added an answer on May 14, 2026 at 7:47 pm

    If it’s possible for you to put the parent and child classes in another assembly, you can make use of internal for the setters. That’s generally how this is dealt with in the wild.

    EDIT:

    Thomas Levesque’s answer gave me an idea:

    class Program
    {
        static void Main(string[] args)
        {
            E myE = new E();
    
            Console.WriteLine("E.N1.Field1 = " + myE.N1.Field1);
            Console.WriteLine("E.N2.Field1 = " + myE.N2.Field1);
        }
    
        public interface IN
        {
            int Field1 { get; }
        }
    
        public class E
        {
            private N _n1 = new N();
            private N _n2 = new N();
    
            public E()
            {
                _n1.Field1 = 42;
                _n2.Field1 = 23;
            }
    
            public IN N1
            {
                get { return _n1; }
            }
    
            public IN N2
            {
                get { return _n2; }
            }
    
            private class N : IN
            {
                private int _field1;
    
                public int Field1
                {
                    get { return _field1; }
                    set { _field1 = value; }
                }
            }
        }
    }
    

    Depending on how you need to expose the child class N, this could work.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 425k
  • Answers 425k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer If you want to do it yourself, you can just… May 15, 2026 at 12:14 pm
  • Editorial Team
    Editorial Team added an answer This error message isn't from Catalyst, it's from your browser.… May 15, 2026 at 12:14 pm
  • Editorial Team
    Editorial Team added an answer Using single quotes echo 'foo is $foo'; will return foo… May 15, 2026 at 12:14 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.