I'm working on my Window Application and i'm using some static members.
public class MyParameter
{
public static string connectionString = "...";
}
Now if I install my application on computer and open two instance of same application. Will 'connectionString' common to the two instances?? Or every instance has its connectionString ?
A static class cannot be instantiated. All members of a static class are static and are accessed via the class name directly, without creating an instance of the class. The following code is an example of a static class, CSharpCorner. We know that all members of the class are static.
Static classes cannot contain an instance constructor. However, they can contain a static constructor.
The static member is always accessed by the class name, not the instance name. Only one copy of a static member exists, regardless of how many instances of the class are created.
Advantages of Static Classes When you try to create an instance to the static class, it again generates a compile time error, because the static members can be accessed directly with its class name. The static keyword is used before the class keyword in a class definition to declare a static class.
The variable static or not is a part of your application memory. When you open 2 instances of your application you create two distinct memory locations in the OS, so there is not any relation between those 2 variables at all.
If you want to create one (relation), you have to look on different IPC (Inter Process Communication) methods available in OS, like:
No, Each application instance are isolated from one another using AppDomain. Thus each application instance will run in a seperate AppDomain and cannot access the variables from other domain. To do communicate with different domain we need to use Remoting , WCF Service
Every instance.
Static members are allocated on a per AppDomain
basis. If you were to spawn a new AppDomain
from within your current one.. they would be different.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With