Question: I have a static double variable in a static class. When I create a specific class, I use the double variable as one of the args of the constructor. What would be the easiest way of manipulating field of the object by changing the variable in static class.
Code for clarity:

```
public static class Vars
{
    public static double Double1 = 5.0;
}
public class ClassFoo
{
    public double Field1;
    public ClassFoo(double number)
    {
        Field1 = number;
    }
}
class Program
{
    static void Main(string[] args)
    {
        ClassFoo Foo = new ClassFoo(Vars.Double1);
        Console.WriteLine(Foo.Field1 + " " + Vars.Double1); //5 5
        Vars.Double1 = 0.0;
        Console.WriteLine(Foo.Field1 + " " + Vars.Double1); //5 0
        //Foo.Field1 need to be a reference to Vars.Double1
    }
}

```

EDIT that goes beyond the question (no more answers needed, other solution found):

I change some values (fields) very often (at runtime, or at least i would like to change them at runtime) to look for one that is right for me. Implementing:

```
if(KeyDown)
  variable++; 
if(OtherKeyDown)
  variable--;

```

Wasn't convenient enough. I just checked Visual Studio Debugger. It's not good (fast) enough. Have to pause, change and run code code again. Method i presented would be good if changed static variable would change field of the object.

Answer: 
In short: no, you can't do this... at least, not seamlessly.

As noted, this is generally considered to be A Bad Idea™. There is no reference encapsulation for value types, and no simple way to implement a seamless wrapper class to do it because you can't overload the assignment operators. You can use the techniques from the `Nullable<T>` type to get part-way there, but no further.

The big stumbling block is the assignment operator. For the `Nullable` type this is fine. Since it is non-referencing (new values are distinct), an implicit conversion operator is sufficient. For a referencing type you need to be able to overload the assignment operator to ensure that assignment changes the contained data instead of replacing the wrapper instance.

About the closest you can get to full reference is something like this:

```
public class Refable<T> where T : struct
{
    public T Value { get; set; }

    public Refable(T initial = default(T))
    {
        Value = initial;
    }

    public static implicit operator T(Refable<T> self)
    {
        return self.Value;
    }
}

```

This will hold a value of the specific type, will automatically convert to that type where applicable (`Refable<double>` will implicitly convert to `double` when required for instance), but all assignments must be done by referencing the `Value` property.

Example usage:

```
Refable<double> rd1 = new Refable<double>(1.5);
Refable<double> rd2 = d1;

// get initial value
double d1 = rd1;

// set value to 2.5 via second reference
rd2.Value = 2.5;

// get current value
double d2 = rd1;

// Output should be: 1.5, 2.5
Console.WriteLine("{0}, {1}", d1, d2);

```
What you really want to do is have `Vars` be a regular class, not a static class. For all methods and classes that need to deal with the variables contained in `Vars`, you can pass in a reference to that `Vars` instance.

Here is a very simple example program that illustrates the above. Note that you could probably do a lot to improve the design of your program, but this will at least get you going in the right direction, and away from trying to bend the language to do things it can't or shouldn't do.

```
public class SharedVars {
    public static double Foo = 0.0;
}

public class ClassFoo {
    private SharedVars mySharedVars;

    public ClassFoo(SharedVars sharedVars) {
        // save a reference to the shared variables container class for future use
        mySharedVars = sharedVars;
    }

    // here's an example use
    public void ProcessKeyDown() {
        mySharedVars.foo++;
    }
}

class Program {
    static void Main(string[] args) {
        SharedVars sharedVars = new SharedVars();
        ClassFoo foo = new ClassFoo(sharedVars);
        // ... some stuff happens ...
        if(KeyDown)
            foo.ProcessKeyDown();
    }
}

```