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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T23:27:45+00:00 2026-06-17T23:27:45+00:00

I have noticed there are other threads on global variables in c#. Such as

  • 0

I have noticed there are other threads on global variables in c#. Such as integers, strings etc. e.g.

public static int;

But I need to use a “var” which the other thread don’t mention and

public static var;

doesn’t seem to work.

So what I’m asking is it possible to have a “var” as a global variable in c#?

  • 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-17T23:27:46+00:00Added an answer on June 17, 2026 at 11:27 pm

    C# specification (section 26.1) reads:

    [`var is] an implicitly typed local variable declaration …

    It goes further:

    A local variable declarator in an implicitly typed local variable
    declaration is subject to the following restrictions:

    • The declarator must include an initializer.
    • The initializer must be an expression.
    • The initializer expression must have a compile-time type which cannot
      be the null type.
    • The local variable declaration cannot include
      multiple declarators.
    • The initializer cannot refer to the declared variable itself

    So no, you cannot do this. Moreover I would recommend steering away from even thinking about global variables.

    Global variables are not supported by the language. You may find alternatives in public static fields, but this will leak object state and break encapsulation.

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

Sidebar

Related Questions

I have noticed that there are strange requests to my website trying to find
I am implementing the superfish menu and have noticed that there is a funny
I have noticed in the PHP regex library there is a choice between ereg
I have facebook comments on my site. I noticed that when there are 10
I have been exploring patterns in various MV* frameworks out there and today noticed
I have noticed FF, Chrome and Safari behaving such that if you intervene to
We have noticed that component publishing takes a long time. The component we are
I have noticed that if you add a unobtrusive link in a refreshable partial
I have noticed a number of kernel sources that look like this (found randomly
I have noticed that deleted branches in svn is not preserved in git. I

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.