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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T05:57:24+00:00 2026-05-28T05:57:24+00:00

I read other threads like this but they didn’t work for me. I got

  • 0

I read other threads like this but they didn’t work for me.

I got two classes:

public class ClassA 
{
    public string _shouldBeInteger;
    public string _shouldBeBool;
    public string _shouldBeDateTime;
}

public class ClassB : ClassA
{
   public int? shouldBeInteger
    {
        get { return (_shouldBeInteger != null) ? Convert.ToInt32(Convert.ToDouble(_shouldBeInteger)) : new int?(); }
        set { _shouldBeInteger = Convert.ToString(value); }
    } 

  //... same thing with datetime etc.


}

If I now create a new object of ClassB I get

 _shouldBeInteger, _shouldBeBool, _shouldBeDateTime;
 shouldBeInteger,shouldBeBool,shouldBeDateTime

But I want to hide the _variables to the User.
Setting them private in ClassB will override them, but I need to access them in order to parse there string values.

Update

There is a ClassC filling ClassAs’ values, which mainly is the reason why they have to be writeable. There is no way for me to change the way that works, but I’m fully in Control of ClassA and ClassB

ClassC //not changeAble for me
{
 //infomagic filling values of ClassA    
}

Setting ClassA variables to private won’t work, because programmer of ClassA produced it in a strange way.

Solution

Because ClassA needs to be writeable, but not readable to other classes than inheritated, I finally got this:

ClassA 
{ 
  public string _shouldBeInteger { protected get; set; } 
  //and so on
} 

which causes ClassB to work with theese properties, without giving them outside.
Intellisense still shows them, but you might consider using:

 [EditorBrowsable(EditorBrowsableState.Never)]

to solve that.

Thanks to all.

  • 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-28T05:57:24+00:00Added an answer on May 28, 2026 at 5:57 am

    I think you can solve your problem using:

    public class ClassA 
    {
        protected string _shouldBeInteger;
        protected string _shouldBeBool;
        protected string _shouldBeDateTime;
    }
    

    so those variables are accessible to derived classes but not to user.

    EDITED after user update:
    I don’t know if this could be a vali solution for you, but try:

    public class ClassB : ClassA
    {
        public new int? _shouldBeInteger
        {
            get { return (base._shouldBeInteger != null) ?
                         Convert.ToInt32(Convert.ToDouble(base._shouldBeInteger)) : 
                         new int?(); }
            set { base._shouldBeInteger = Convert.ToString(value); }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've read through the two other threads that extract the dll from the application
I've read through other questions but to no avail - I really can't work
I've read the other posts here about this topic, but I can't seems to
I've read through a few other threads on here, though none of them really
I have read other related question but i cant really get them to relate
my jQuery.ajax return JSon object. I firstly read other articles. but their response text
I've read several other questions about material in order to learn RoR. But my
I've read a few other questions that seem similar but I'm still very confused,
I would like to compare two collections (in C#), but I'm not sure of
If you read other people's source code, how do you approach the code? What

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.