Sagotharan
Sagotharan

Reputation: 2626

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

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?.

Upvotes: 2

Views: 493

Answers (1)

Beatles1692
Beatles1692

Reputation: 5320

Your myConnString field should be static too :)

Upvotes: 1

Related Questions