I found a similar question, but it was closed and didn't answer this for me.
I have a static class Globals that holds some variables and another Class Stuff that does things. I want Stuff to see if Globals exists and then change some of its variables to the values stored in Globals. I tried
try{
for (int i = 0; i < Globals.StuffArray.Length; i++)
StuffArray[i] = Globals.StuffArray[i];
}
catch
{
}
in the constructor for Stuff.
This obviously doesn't work, but the idea was to try to change the variables and to throw an error, that get's ignored, if Globals.StuffArray doesn't exist.
I would still like to know if it's possible to do this, but I'm not solving my problem this way, I added a setter to change the defaults from Globals and that works fine.
update for clarity:
I wanted to make it so that I could leave out Globals and still have Stuff compile.
Update:
In jvascript you can have something like
if (condition1) var x = 0;
if (x) doStuffTo(x);
JavaScript does stuff in the background to make that logical. I wanted to know if C# can do something similar.
To reiterate: I asked because I'm curious if this is possible. Some of the responses seem to have missed the part where I said I'm not going to solve my problem this way, the problem was easily solved by making a property for Globals to change.