An object reference is required for the non-static

2020-04-12 13:01发布

问题:

I want to pass myConnString in all forms. ( I am working in winform and mysql C#. ) So I tried this link.

   static class GlobalClass
    {
        private string myConnString = "";

        public static string GlobalVar
        {
            get { return myConnString; }
            set { myConnString = value }
        }
    }

The above code gives the error :-

An object reference is required for the non-static field, method, or property

What is the mistake?.

回答1:

Your myConnString field should be static too :)



标签: static