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

The Archive Base Latest Questions

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

Constructor Conundrum, I have these two constructors. One is for making a copy of

  • 0

Constructor Conundrum, I have these two constructors. One is for making a copy of the class and the other is the standard constructor. I need to call the first one so that I can use the rule in it. I shouldn’t have to repeat code so I am looking for a way to keep from overwriting the two dimensions.

public SprinklerLineModel()
    {

        NearCrossMainDimension = new PipeDimensionModel();
        FarCrossMainDimension = new PipeDimensionModel();

        this.AddValidationRule(Rule.CreateRule(() => BranchLineDiameter, RuleMessage.GREATER_THAN_ZERO, () => BranchLineDiameter > 0));
    }

    /// <summary>
    /// Copy Constructor
    /// </summary>
    /// <param name="sprinklerLineModel">Original copy of sprinklerLineModel</param>
    public SprinklerLineModel(SprinklerLineModel sprinklerLineModel)
        :this()
    {
        this.EstimatedFlow = sprinklerLineModel.EstimatedFlow;
        this.EstimatedPressure = sprinklerLineModel.EstimatedPressure;
        this.NearCrossMainDimension = new PipeDimensionModel(sprinklerLineModel.NearCrossMainDimension);
        this.FarCrossMainDimension = new PipeDimensionModel(sprinklerLineModel.FarCrossMainDimension);
        this.BranchLineDiameter = sprinklerLineModel.BranchLineDiameter;
        this.LeadLinePipeFittingLength = sprinklerLineModel.LeadLinePipeFittingLength;
        this.ExbPipeFittingLength = sprinklerLineModel.ExbPipeFittingLength;

        this.IsDirty = sprinklerLineModel.IsDirty;
    }

I want to be able to call the default constructor with out overwriting the two variables. Any help would be appreciated.

I suppose I could check and see if they are null but that doesn’t seem like it is the best way.

Thanks

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

    I would extract an initialization method and call said method from both constructors.

    public SprinklerLineModel()
    {
        NearCrossMainDimension = new PipeDimensionModel();
        FarCrossMainDimension = new PipeDimensionModel();
        Init();
    }
    
    public SprinklerLineModel(SprinklerLineModel sprinklerLineModel)
    {
        this.EstimatedFlow = sprinklerLineModel.EstimatedFlow;
        this.EstimatedPressure = sprinklerLineModel.EstimatedPressure;
        this.NearCrossMainDimension = new PipeDimensionModel(sprinklerLineModel.NearCrossMainDimension);
        this.FarCrossMainDimension = new PipeDimensionModel(sprinklerLineModel.FarCrossMainDimension);
        this.BranchLineDiameter = sprinklerLineModel.BranchLineDiameter;
        this.LeadLinePipeFittingLength = sprinklerLineModel.LeadLinePipeFittingLength;
        this.ExbPipeFittingLength = sprinklerLineModel.ExbPipeFittingLength;
        this.IsDirty = sprinklerLineModel.IsDirty;
        Init();
    }
    
    void Init()
    {
        this.AddValidationRule(Rule.CreateRule(() => BranchLineDiameter, RuleMessage.GREATER_THAN_ZERO, () => BranchLineDiameter > 0));
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Constructor Delay.vkMessages.vkMessages(string, System.DateTime, string, bool, string) cannot call itself.I have another class, copy of
I have two constructor : function clsUsagerEmailUserName($nickName, $email) { $this->nickName = $nickName; $this->email =
why is the second constructor shadowing the first? class RC2{ private; bool keyset; public:
One of the constructor defined in String class is String(char chars[],int startindex,int *numChars*) ,
I have a constructor for my Arduino-code which is something like the following: class
The default copy constructor that is synthesized by the compiler for a class that
I have a constructor like as follows: public Agent(){ this.name = John; this.id =
In the constructor of my class, I map the current object ( this ),
In a constructor in Java, if you want to call another constructor (or a
In a C# constructor, that ends up with a call to this(...) , the

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.