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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T05:49:31+00:00 2026-05-11T05:49:31+00:00

First of all, the static keyword. I’ve read several articles and past threads on

  • 0

First of all, the static keyword.

I’ve read several articles and past threads on here covering the static keyword. I haven’t found many scenarios listed of when I should use it. All I know is it doesn’t create an object on the heap which tells me it would be good from a performance point of view for an object used a lot.

Is there any other reason to use it?

Also, I have read something about the static keyword and how it shouldn’t be used with instance variables or to alter state. Can someone clarify this? It seems like this is a case of 2+2 but I can’t get an answer (missing a few fundamental and simple pieces of knowledge).

Lastly, on the topic of thread safety, what should I look for in my code to get an idea of thread safety?

I have posted this in VB.NET too because I don’t think different languages (C#/VB.NET) will have different rules.

Thanks

  • 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. 2026-05-11T05:49:32+00:00Added an answer on May 11, 2026 at 5:49 am

    The static keyword means something different in C, but in C# and Java it declares methods and variables to be of the class rather than an object.

    You would want to use it for methods and variables that don’t need any data from a particular object, but use the same data for each object of that type.

    For example String.Format() is a static method of the String class. You call it in your code without creating a String instance. Likewise, Math.Pi would be a class variable.

    But something like a length method doesn’t make any sense unless it acts upon a specific instance of a string, so it would have to be an instance method. E.g., x = ‘hello’.Length();

    So if you want your method to be called with just the class name and not on an object, then you make a static method. Note that such a method can only reference static variables and call static methods, as it doesn’t have an object with which to reference non-static members.

    In C, the static keyword denotes file scope linkage. A top-level static variable or function does not get its name exported to other compiled object code. So two files can declare static variables of the same name and not create a conflict. We don’t have this problem in C#, because there are namespaces, and private, protected, and public keywords to denote visibility.

    Yet another meaning is for static variables within a function in C. These variables retain their value between calls to the function. For example, you could use one to count the number of times the function has been called. Static variables in C# also have this property, but you don’t declare them within the method as in C, just within the class.

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

Sidebar

Related Questions

First of all, Beginner here. I'm using this code. class MDArrays { public static
First of all, yes I've read documentation for DO statement :) http://www.postgresql.org/docs/9.1/static/sql-do.html So my
First of all I've gone through dozens of posting here on SO and google
First of all, I read erickson's useful reply to Why can’t I define a
First of all... Sorry for this post. I know that there are many many
First of all, we are talking about Keepass here. The file in question is:
Hi all first post here :) Let's start with a snippet of the code
First of all, this isn't for a keylogger, it's for an input in a
first of all some details: I configured security as below in web.xml view plaincopy
First of all, I'm quite new to the Android and JAVA world (coming from

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.