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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T22:29:12+00:00 2026-05-26T22:29:12+00:00

So basically I’ve come across some readonly properties on this one class that the

  • 0

So basically I’ve come across some readonly properties on this one class that the writer of the class told me I could make settable for a specific task. Problem is, they get their value through manipulation most of the time, not directly from a private variable in the class.

Example:

public decimal? AccruedInterest
{
    get
    {
        if (this.Result != null)
        {
            return this.GetExchangedCurrencyValue(this.Result.AccruedInterest.GetValueOrDefault(decimal.Zero));
        }
        return null;
    }
}

So if I want to add a setter, I don’t want to worry about setting that Result object because I’m not sure if on it’s way back out it’s going to be drawn correctly.

Would I be able to do something like this?

private decimal? _AccruedInterest;
public decimal? AccruedInterest
{
    get
    {
        if (this._AccruedInterest.HasValue)
        {
            return this._AccruedInterest.Value;
        }
        if (this.Result != null)
        {
            return this.GetExchangedCurrencyValue(this.Result.AccruedInterest.GetValueOrDefault(decimal.Zero));
        }
        return null;
    }
    set
    {
        this._AccruedInterest = value;
    }
}

Or do any of you see issues that could arise from this (besides the fact that it’s now changeable)?

  • 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-26T22:29:12+00:00Added an answer on May 26, 2026 at 10:29 pm

    Well your only problem with this is if they set the value to be null and you want your property to return null rather than evaluate the if statement.

    But you might not allow them to set null, in which case you should add a check in the setter.

    set 
    { 
        if (value == null)
            throw new NullArgumentException("AccruedInterest");
        this._AccruedInterest = value;
    }
    

    If it is valid for them to set null, you probably need another boolean flag to tell if the value has been set.

    private bool _accruedInterestSet;
    private decimal? _accruedInterest;
    public decimal? AccruedInterest
    {
        get
        {
            if (this._accruedInterestSet)
            {
                return this._accruedInterest; //don't return .Value in case they set null
            }
            if (this.Result != null)
            {
                return this.GetExchangedCurrencyValue(this.Result.AccruedInterest.GetValueOrDefault(decimal.Zero))    ;
            }
            return null;
        }
        set
        {
            this._accruedInterestSet = true;
            this._AccruedInterest = value;
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Basically I need to know how to make this work. I removed one of
Basically we've noticed that on some computers setting the JVM option -Xmx (max heap
Basically I have this server app I built in vc#, and for some reason
Basically I would like to have some dictionary that is an abstaction over legacy
Basically what I want to do it this: a pdb file contains a location
Basically, something better than this: <input type=file name=myfile size=50> First of all, the browse
Basically I have some code to check a specific directory to see if an
Basically I’ve heard that certain conditions will cause .NET to blow past the finally
Basically I'm trying to accomplish the same thing that mailto:bgates@microsoft.com does in Internet Explorer
Basically my task is to make the counter on a micro controller board count

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.