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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T03:27:39+00:00 2026-06-05T03:27:39+00:00

If I have a class like this: public class Foo { public IEnumerable<Bar> Bars

  • 0

If I have a class like this:

public class Foo
{
    public IEnumerable<Bar> Bars { get; set; }

    public Foo()
    {
        Bars = new List<Bar>();
    }
}

At some stage I re-factor the class and add a secondary constructor which implements the first one like this:

public class Foo
{
    public IEnumerable<Bar> Bars { get; set; }

    // some more properties were added

    public Foo()
    {
        Bars = new List<Bar>();
    }

    public Foo(string parameter): this()
    {
        .... some code here
    }
}

I could have also written it similar to this:

public class Foo
{
    public IEnumerable<Bar> Bars { get; set; }

    // some more properties were added too

    public Foo()
    {
        InitilizeFoo();
    }

    public Foo(string parameter)
    {
        InitilizeFoo();
        .... some code here
    }

    private void InitializeFoo()
    {
        Bars = new List<Bar>();
    }
}

Seeing both approaches work in this scenario, is there a benefit or drawback in using one over the other?

Is inheriting constrcutors more efficient and making that code execute faster or is there a drawback which I don’t know about making the second implementation more efficient instead?

  • 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-05T03:27:42+00:00Added an answer on June 5, 2026 at 3:27 am

    One of the key benefits in having one constructor call another constructor is that you can set read-only fields that way, you can’t do that by calling a non-constructor method.

    For example:

    public class Foo
    {
        private readonly int myNumber;
    
        public Foo() : this(42)
        {
        }
    
        public Foo(int num)
        {
            myNumber = num;
        }
    }
    

    Performance wise, it’s probably no more or less efficient to call another constructor than to call another method, but it is more readable, in my opinion, for a constructor to call another constructor than to call a separate, private method whose only point is to be called by a constructor.

    There could, of course, be situations when having a separate method makes sense, and it’s certainly not “wrong” per se. Chaining constructors just reads better to many for most uses, and there is no negative performance impact.

    UPDATE: I performed 10,000,000 iterations of each way (chained vs private initialization method) and the results were so close they were nearly indistinguishable:

    Initializer Method took: 84 ms for 10,000,000 iterations, 8.4E-06 ms/each.
    Chained Constructors took: 81 ms for 10,000,000 iterations, 8.1E-06 ms/each.
    

    So really, performance-wise there is nearly no benefit either way. The main benefit is with chained constructors you can set readonly fields, and in most cases it is more readable.

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

Sidebar

Related Questions

I have the a class Foo like this: class Foo { public int id{get;set;}
I have a class like this: public class Contest { List<ContestTeam> Teams { get;
I have a class like this: private class MyClass { [DisplayName(Foo/Bar)] public string FooBar
i have a class like below public class Foo<T> { public List<T> Items{ get;
Assume I have a class like this: public class Foo { public Bar RequiredProperty
Suppose I have a class like this: class Foo { std::vector<int> bar; public: std::vector<int>&
I have a class like this public class foo { private void getThread() {
I'm using MVC3 and I have a model like this: public class Foo {
If I have a class, Foo, looking like this... class Foo { public string
Consider this abstract class public abstract class Foo { public Injectable Prop {get;set;} }

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.