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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T08:22:06+00:00 2026-06-15T08:22:06+00:00

I found a class similar to the follow one: class Controller { private readonly

  • 0

I found a class similar to the follow one:

class Controller
{
    private readonly IDataContext _myContext = new DataContext("connectionstring");

    public Controller(IDataContext context){
        _myContext = context;
    }
}

Given instances are created as bellow:

var controller = new Controller(new DataContext("anotherconnectionstring"));

What I would like to know is which will be the final instance assigned to _myContext field? The one passed as an argument or the one used as RHS in the declaration?

  • 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-15T08:22:08+00:00Added an answer on June 15, 2026 at 8:22 am

    All fields which are initialized explicitly in a class definition are moved into the default class/type constructor which will be called before any other explicitly defined parametrized constructor. So final value willl be a value you are passing in custom constructor.

    MSDN, Fields (C# Programming Guide)

    Fields are initialized immediately before the constructor for the
    object instance is called. If the constructor assigns the value of a
    field, it will overwrite any value given during field declaration.

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

Sidebar

Related Questions

I found this code here class Usable; class Usable_lock { friend class Usable; private:
I found out this morning that proc.new works in a class initialize method, but
I've found myself writing a lot of code similar to this: $('.selector').addClass(condition ? 'class'
I found myself staring at code that looks similar to this: private double? _foo;
In Web API I had a class of similar structure: public class SomeController :
I've found the class WordnetSynonymParser in org.apache.lucene.analysis.synonym but there aren't examples of its usage
I found this great class, all works well except... I spcify the output directory
I've found a great class to extend the abstract File Observer class... import android.os.FileObserver;
com/jniwrapper/win32/ie/WebBrowser class not found. From where can I download jniWrapper library. I have downloaded
We have encountered a very strange class not found problem in our web app

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.