Greetings-
I have 2 classes. One is called “Programs” and the other is called “Logs”. The class called Programs has public const string m_sEnviron = ""; near the top and I need to check what the m_sEnviron variable is set to through my class called Logs. The variable m_sEnviron will get set from a scheduler called Tidal so how can I check its value from a different class. If this is not the best to do this then please let me know what the better ways are.
Thanks in advance.
Regards,
Namespace NightScripts
{
class Program
{
public static string m_sEnviron {get; set;}
static void Main(string[] args)
{
}
//Lots of other functions...
}
class Logs
{
//I try to get access to m_sEnviron but it will not show after I type Program.
}
}
Well,
m_sEnvironisn’t a variable (/field) – it is aconst; it is always"".If it was a static property (or field), then
Programs.m_sEnviron. If it was an instance property (or field) thensomeInstance.m_sEnvironshould work, since it ispublic– but I would rename it.I expect you mean it to be a
staticfield; which can work, but you should at least be a little cautious that this doesn’t necessarily play nicely if you start using multiple threads, etc. And public fields are generally best avoided (prefer private fields and public properties).For example:
would be a public, static property easily accessible as
Program.Environ.