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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T16:14:52+00:00 2026-05-27T16:14:52+00:00

I am a bit confused about what the Initialize method is typically used for

  • 0

I am a bit confused about what the Initialize method is typically used for in a constructor.

Why can’t I just put everything in the constructor and why does the sample below call the initialize method?

    private IAzureTable<Product> _productRepository;

    public ProductService(string dataSourceID)
    {
        Initialize(dataSourceID);
    }

    private void Initialize(string dataSourceID)
    {
        this._productRepository = StorageHelper.GetTable<Product>(dataSourceID);
    }

Is there a convention that is normally used?

In this example do I need the word this in the Initialize method?

  • 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-27T16:14:53+00:00Added an answer on May 27, 2026 at 4:14 pm

    Why can’t I just put everything in the constructor and why does the sample below call the initialize method?

    You can put it all in the constructor. In this simple case, you should. Constructors are for initializing your object.

    Sometimes you have something more complicated though:

    • Sometimes you will want a separate Initialize method because you want to call it at a separate time from construction.
    • Sometimes you want one because you are writing multiple constructors, and you want to share some of the implementation between them.
    • Sometimes your initialization is complicated, and you want to give the pieces of it good names so you know what your code is doing. So you break those pieces into separate methods.

    None of these are the case for this code, so I’d just skip it and throw the code in the constructor.

    Is there a convention that is normally used?

    No. People do whatever is the easiest to read and understand, whatever requires the least extra code to be written, and whatever causes the least duplication of code.

    However, if you’re making the Initialize method public, and not calling it from the constructor, I highly recommend you call it Initialize. Design it to only be called once.

    In this example do I need the word “this.” in the Initialize method?

    No. You never need to use this to access class members unless you have another local variable with the same name. Here’s such a case:

    public class Something
    {
        private string someValue;
    
        public class Something(string someValue)
        {
            // must use "this" to access the member variable,
            // because a local variable has the same name
            this.someValue = someValue;
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am bit confused about ADO.Net Data Services. Is it just meant for creating
I'm a bit confused about how many controllers I need, and when I can
I'm a bit confused about the object references. Please check the examples below: class
I am a bit confused about this function definition in Prolog: sample(X,[X|Tail]) :- member(X,Tail).
I'm a little bit confused about simple program which I wrote, can You please
I am a bit confused about overriding vs. hiding a method in C#. Practical
I am a bit confused about encapsulation. In general (or in Obj-C), does it
I am a bit confused about the license. Can anyone tell me if I
I am a bit confused about SQL CLR. When i use the below query
I'm a bit confused about this. Does XMLHttpRequest work on a remote URL or

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.