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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T07:57:05+00:00 2026-05-26T07:57:05+00:00

I’m just curious about which among variables and methods inside a class were initialized

  • 0

I’m just curious about which among variables and methods inside a class were initialized first whenever a class is initialized. I have this code below to give you idea of what I am really troubled of:

 public static class
 {
    private static int _revisionNumber;
    private static Dictionary<string, bool> _jobBoardList;
    private static readonly string ConnectionString = GetAppConfigData("JobBoardAutomationConnectionString");
    private static readonly string ImportRunId = JobProcessingUtility.GetGuid();
    private static readonly string TimeStampGuidString = CreateTimeStampGuidString(ImportRunId);
    private static string _tempDirectoryForExportFiles;
    ........

    private static string GetAppConfigData(string key)
    {
        return ConfigurationManager.AppSettings[key];
    }
 }

You can notice that i have a variable named “ConnectionString” and it is acquiring it’s value from the method named GetAppConfigData(string key), I’m just curious of which among methods and variables inside a class were created first whenever a class(not instances of the class) is initialized. Can someone please explain to me which was constructed first so that I could have a good idea of how to create classes and methods.

  • 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-26T07:57:06+00:00Added an answer on May 26, 2026 at 7:57 am

    The variables are initialized in textual order (i.e. the order in source code), as per section 10.5.5 of the C# 4 specification:

    Thus, when a class is initialized, all static fields in that class are first initialized to their default values, and then the static field initializers are executed in textual order.

    So in your case, the initializer for ConnectionString would be executed before JobProcessingUtility.GetGuid() is called.

    However, it’s generally not a good idea to rely on this, as it makes the code brittle – the simple act of reordering static variables could break the code. I’ve come across situations where it’s somewhat hard to avoid, but where possible you should avoid it.

    Note that when there is still room for ambiguity with partial classes – the spec doesn’t make any guarantees there, although I’d expect all the static fields declared in one source file to be initialized, then all the ones in the other(s) to be initialized, with the order preserved within each source file. But no guarantees 🙂

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

Sidebar

Related Questions

I have just tried to save a simple *.rtf file with some websites and
this is what i have right now Drawing an RSS feed into the php,
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I have a text area in my form which accepts all possible characters from
I have some data like this: 1 2 3 4 5 9 2 6
For some reason, after submitting a string like this Jack’s Spindle from a text
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I am trying to understand how to use SyndicationItem to display feed which is
I used javascript for loading a picture on my website depending on which small

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.