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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T20:21:36+00:00 2026-05-11T20:21:36+00:00

I was working in the Microsoft.Ink dll recently using C# and was debugging a

  • 0

I was working in the Microsoft.Ink dll recently using C# and was debugging a problem (which is not related to this) I noticed, that when I was debugging it, ink objects had a strokes object, which had an ink object, which had…. etc.

This confused me, as I was under the assumption you could not do this (I come from a C++ Background)

But I ignored it, solved the problem, and moved on. Today, I run into a similar problem, as I look at a class which had a private member which was the same class as itself.

public sealed class Factory
{

    private static Factory instance = new Factory();
}

How is that even possible? I can now call instance.instance.instance.instance…etc. This, as you can imagine, hurts my mortal brain, and I’m sure it can’t be good on the computer either. How does the compiler deal with this? And Just how deep does the rabbit hole go?

  • 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-11T20:21:36+00:00Added an answer on May 11, 2026 at 8:21 pm

    Because it’s static and therefore there is only one copy of the variable instance within the AppDomain.

    What you’re thinking of is this:

    public class Foo
    {
      private Foo lol = new Foo();
    }
    

    Notice, everything here is instance, not static.

    As the commenters noted (long ago), this is valid syntactically, but would result in a StackOverflowException being thrown, as the assignment requires construction, and construction creates a new assignment. One triggers the other in a cycle that ends when the call stack reaches its maximum length.

    In OP’s example, assignment requires construction, but the assignment is triggered by the static constructor, not the instance constructor. The static constructor only executes once within an AppDomain, in order to initialize the class’ Type. It isn’t triggered by instance construction, and so (in OP’s example) won’t result in a stack overflow.

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

Sidebar

Related Questions

I am working with Microsoft SQL Server 2005, and when I execute this query:
I am working with Server object from Microsoft.SqlServer.Management.Smo namespace. How i can check that
I'm working on a library of custom controls and I'm stuck on this error.
I'm working in Microsoft SQL Server 2005 and need to do an analysis of
I'm working with Microsoft Team Foundation Server and MSDN has been fantastic so far
I'm working in the microsoft world and needing to create a transaction processing webservice.
Update: Microsoft have now reproduced the bug and are working on a fix. Whilst
I'm currently working my way through the Microsoft SQL Server 2008 - Database Development
Okie, I've searched it in SO and I've not found it. Can someone tell
How is should a HLOCAL data type be converted to a LPTSTR data type?

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.