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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T19:21:10+00:00 2026-06-01T19:21:10+00:00

Someone once said : a global variable is really a variable you create to

  • 0

Someone once said:

a “global variable” is really a variable you create to simply “hold some information” because your object model is weak, and you haven’t found a “true purpose” for the variable to exist. Global variables are almost always a sign of a larger architectural deformity.

That might be true. But I don’t know of any good example of any big and good program made without global variables, and certainly not used as little as above suggested. Scope is the actual key. You can say in a program with only one class that its parameters are not global vars. But they are.

Anyway…

I’m still grasping the concept of singleton and, as far as I can tell, they actually make no sense in C#. Also I get the feeling that when having a global state can’t be avoided we still should avoid simply using a public class full of static properties:

So, if not singletons nor a public class, what should we do to have global vars in C#?

And when are we supposed to use them? Assuming they most likely can’t be avoided. Ever.

And why should we avoid using a static class or static in general? If that’s indeed the case for C#.

In one sentence: What are the best practices on using global variables in Csharp?

  • 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-01T19:21:11+00:00Added an answer on June 1, 2026 at 7:21 pm

    It’s all a matter of context.

    If you can determine the ambient variables that you need for a computation, you can wrap that computation in a bigger context where those global-looking variables have a narrower scope to inhabit (they’re now local to the context).

    This is better because now you can have multiple instantiations of your context, that should work independently and not interfere with each other. It’s also called a reentrant context.

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

Sidebar

Related Questions

Someone I worked with once said that shared_ptr was unsafe and would slice when
per the discussion of R programming styles, I saw someone once said he puts
Someone once told me VB.net had some built-in function to check if two rectangles
I am trying to create an activity that changes backgrounds once someone clicks (and
Someone once showed me a cool IntelliJ Idea plugin that would show all the
I want to add a custom message once someone saves a specific content-type telling
I have a PHP login which sets 2 cookies once someone login. The problem
Someone told me once there was a good novel around the story of the
I recall reviewing someone else's PHP code once and he had a function or
Someone once hinted that doing this in a header file is not advised: using

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.