hi everyone ,
Im having problems in saving values in the static variables. Here it is how it goes
i have 3 projects in a solution. Lets say A , B and C.
I have added the references of C in A and B
A calls C and saves a value .
Later B calls C but B get the value as 0(even though this variable wasnt used anywhere in between)

The problem is the variable j gets the value 0 when the method recieveEle is called.but i want the value to be j=4.
when i set the breakpoint in B where the new instance is created , thats where j is set to 0.I know that the problem is because two independent instances are created. But i have a static variable which is also declared where the value shouldnt be lost.

would be gratefull for any help

this is how my code looks like

A:

public   class Program 
    {
 static void Main(string[] args)
        {
...
...
 Mediator.Class1 mediat = new Mediator.Class1();
  mediat.test(4);
  waitHandle.WaitOne();
         }
   }

B:

..
...

 Mediator.Class1 mediat = new Mediator.Class1();
           mediat.recieveEle(request);

C:

public   class Class1
    {
 public static int m_globalVar = 0;
int j;

     public static int GlobalVar
        {
            get { return m_globalVar; }
            set { m_globalVar = value; }
        }
 public void test( int i)
        {
         
            GlobalVar = i;
        }
        public void recieveEle(Element ele)
        {
            j = GlobalVar;

        }
    }

what the value of request in

Mediator.Class1 mediat = new Mediator.Class1();
mediat.recieveEle(request);
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.