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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T03:57:38+00:00 2026-06-18T03:57:38+00:00

I had a class with 6 properties which were basically 3 pairs of properties,

  • 0

I had a class with 6 properties which were basically 3 pairs of properties, each pair containing data about one thing. All of these properties were public, but setting them was protected. It is shown in the code below:

public class MyClass
{
    public Data1Type Item1Data1 { get; protected set; }
    public Data2Type Item1Data2 { get; protected set; }
    public Data1Type Item2Data1 { get; protected set; }
    public Data2Type Item2Data2 { get; protected set; }
    public Data1Type Item3Data1 { get; protected set; }
    public Data2Type Item3Data2 { get; protected set; }
}

Because each pair of properties was basically treated as one item, I decided to make a struct which looks like this:

struct Item
{
    Data1Type Data1;
    Data2Type Data2;
}

So I replaced each pair of properties with one Item struct.

The problem I’m facing now is that I can’t find a way to have the same protection level I had before, with the 3 pairs of properties. I want everything outside MyClass to be able to get the properties inside the Item structs, but only MyClass and classes derived from it to be able to change the properties inside the Item structs.

How can I do such a thing? Is it even possible?

  • 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-18T03:57:39+00:00Added an answer on June 18, 2026 at 3:57 am

    You can make your struct read-only to retain control over the values. This is a pattern used in parts of .NET:

    struct MyStruct
    {
        public readonly int Field1;
        public readonly int Field2;
    
        public MyStruct(int i, int j)
        {
            Field1 = i;
            Field2 = j;
        }
    }
    

    Then you can create your properties the same way you did before, knowing that the values inside the struct will remain unchanged unless you go through the property setter.

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

Sidebar

Related Questions

i had created a class with two properties one of datetime datatype and other
I've messed with Access a little bit in the past, had one class on
I had to write a class of some sort that overrides __getattribute__ . basically
lets take this example, which I think covers all my questions: class SomeClass {
I just recently learned about the Properties class in java, and I'm trying to
I have a settings class, which has some properties for usability and to restrict
The story: I had class User and class Organization: User. I did not use
I had a class: public class Constant { public static string ConnString = ConfigurationManager.ConnectionStrings[ConnString].ConnectionString;
I had a class loader working although I am now getting an error after
I was working with inheritance in WTForms . I had next class: class MyForm(WTForms):

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.