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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T03:07:42+00:00 2026-05-30T03:07:42+00:00

Possible Duplicate: What is the static variable initialization order in C#? For fun i

  • 0

Possible Duplicate:
What is the static variable initialization order in C#?

For fun i ran this code

I was not expecting 2 2 3. I was expecting a compiler error (circlur dependency) or 8 5 3.

What are the rules to initialization order in C#?

-edit- i tried making a not static and i got what i expected. Why is b 2 before and now 5. I don’t think i’m going to like the rules… Luckily i never do anything like this so i haven’t had a problem.

using System;

public class Test
{
        public static void Main()
        {
                A.t();
        }
}

class A
{
    static int a = B.b + c;
    public static int c = 3;
    static public void t()
    {
        Console.WriteLine("{0} {1} {2}", a, B.b, c);
    }
}
class B
{
    public static int b = A.c+2;
}
  • 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-30T03:07:43+00:00Added an answer on May 30, 2026 at 3:07 am

    Initialisation is per-type when needed (beforefieldinit notwithstanding). Withing a class: “textual order”:

    §17.11 in ECMA 334:

    If a class contains any static fields with initializers, those initializers are executed in textual order immediately prior to executing the static constructor.

    It doesn’t apply for instance fields, since you can’t use instance values in a field initializer.

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

Sidebar

Related Questions

Possible Duplicate: java String concatenation How to Improve performance of this chunk of code
Possible Duplicate: static members and LNK error in C++ What does it mean to
Possible Duplicate: Use a variable within a variable? Java Hi this is a general
Possible Duplicate: Where do I have to declare static variables? I've seen code like
Possible Duplicate: When should static_cast, dynamic_cast and reinterpret_cast be used? With this C++ code,
Possible Duplicate: Problem when loading php file into variable (Load result of php code
Possible Duplicate: does these code has memory leakage?? static private ArrayList seriesColors = new
Possible Duplicate: What static analysis tools are available for C#? Guys, I'm looking for
Possible Duplicate: When to Use Static Classes in C# Questions in the title..........i would
Possible Duplicate: Why not use tables for layout in HTML? Under what conditions should

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.