Linked Questions

-5 votes
1 answer
1k views

I created a static variable in a class and incrementing in the constructor, thinking that whenever I created an instance to the class, the static variable will be reset to 0. To my surprise, the first ...
Sunilkumar Mandati's user avatar
-7 votes
1 answer
1k views

Does anybody know how to modify a static variable from a different script in Unity?
DubGamer87's user avatar
0 votes
1 answer
519 views

I am new to C# and I came across the following query. Since a class is not an object but just a blueprint(template), how is it possible to define static members on the class and access them by using ...
Unknown developer's user avatar
-4 votes
1 answer
548 views

I'm wondering I can't reach static class field from instance variable class aa { public static string b = "bb"; } Console.WriteLine(aa.b); //fine aa f = new aa(); f.b ...
vico's user avatar
  • 18.5k
3 votes
4 answers
45k views

I am new at programming and I am trying in vain to create a function that returns an auto increment id, however the code isn't working and I'm sure there's something missing even though I don't get ...
Ricardo's user avatar
  • 87
5 votes
5 answers
3k views

I've been working in C for the past couple of years and I've managed to get use to putting single-purpose, static variables near where they are used within my code. While writing a very basic method ...
RLH's user avatar
  • 15.8k
6 votes
4 answers
2k views

I have to ask this question because I feel that only experienced programmers can know the pros and cos of static members in a class. I've read books explaining about static members, I've also used ...
King King's user avatar
  • 63.5k
4 votes
1 answer
6k views

I came to know that, From MSDN: C# does not support static local variables (variables that are declared in method scope). And here: The static modifier can be used with classes, fields, methods,...
Noor A Shuvo's user avatar
  • 2,885
2 votes
4 answers
525 views

Update for future readers: If you find this text too long: This is a race condition due to a static variable. What you are reading below is showing how confusing this can become for someone who is ...
Leif's user avatar
  • 2,170
1 vote
1 answer
3k views

Running the bellow code you can see that there is a different between CallContext and AsyncLocal. using System; using System.Runtime.Remoting.Messaging; using System.Threading; namespace ...
Fitzchak Yitzchaki's user avatar
1 vote
3 answers
2k views

i was writing code in MVC and i don't' understand behaviours public properties in my project!! my code its very simple, increment property. When i clik on button the property is overwrites. Its work ...
rejentt's user avatar
  • 81
0 votes
3 answers
2k views

I have four game objects with the same script and the same bool, when one of them get hit by ray the bool state is true, but the function will not start because the other three game objects is set to ...
Botros's user avatar
  • 3
0 votes
5 answers
684 views

Im gonna paste the code first so you can see what Im talking about: namespace Radni_sati { public class Blagdani { public List<Blagdani> Blagdani_lista = new List<Blagdani>(); ...
Marko Petričević's user avatar
1 vote
1 answer
708 views

I am new to C# programming and I am currently using many static variables in my code. Below is one example: class Program { public int I//Can be used to access the variable i anywhere from the ...
JOW's user avatar
  • 244
0 votes
4 answers
257 views

I've tried searching this but I cant find a clear answer to my question. When can you actually alter a static variable? From my understanding you can only change it within the static constructor. ...
Dan Beaulieu's user avatar
0 votes
1 answer
673 views

I know if I have a static class with static properties, then that state will be shared with all threads that are running. 1) But lets say I have a non static class with a static property will that ...
marwaha.ks's user avatar
1 vote
4 answers
396 views

I am working through C# in a Nutshell from Joseph Albahari & Ben Albahari which has been a great book by the way and am reading through the topic on static fields in C#. They have this example ...
tokyo0709's user avatar
  • 2,017
-1 votes
4 answers
102 views

I am very new to programming so I was trying to do some work with and got stuck with my problem. Here is my code: //Properties private static readonly List<string> category = new List<string&...
Rufat's user avatar
  • 3
0 votes
2 answers
217 views

I want to use a static List with an interface in .net I wonder where in the code I should declare my List : in the interface class, in the derived classes, or somewhere else ? For the moment I have it ...
Gui Gui's user avatar
0 votes
1 answer
150 views

So I'm making a FPS Survival game. I made a GameManager script which handles the Enemy Spawning part of the game. My EnemyAttack script handles the enemies attacking. Problem is, when the first enemy ...
byIcee's user avatar
  • 145
0 votes
4 answers
157 views

I'm trying to figure out what static vars are. They can be access without instantiating the class but what other benefits do they have and when should they be used? For example, my class has a ...
panthro's user avatar
  • 24.2k
0 votes
1 answer
64 views

I have class FrontModel contains some fields from XAML: public class FrontModel() { public static string LoginName { get; set;} public static string userPass; public static string Domain { get; ...
4est's user avatar
  • 3,198
0 votes
1 answer
72 views

Here is my problem, I fetch a json from a webservice and deserialize it into an object. Now, I want this object and its values to be accessible from anywhere in the program, how can I do that ? PS: ...
En_Tech_Siast's user avatar
0 votes
1 answer
57 views

This is the testing class: namespace ScopedTest.Data { public class TestingClass { public static string? Name { get; set; } = "HAHA"; } } and here is the class im ...
Am Ma's user avatar
  • 41
0 votes
1 answer
36 views

class A { } class B { static A a; } What does this mean? dose it mean i can have only instance of class A inside class B?
user1931544's user avatar