Static field error
Static field error
(OP)
I am trying to pass back an instance of an object from a method but I get the error:
From a console program:
The object temp2 gets created fine.
But I get a compiler error on the GetDataSet() method:
An object reference is required for non-static field, method, or property
I do this all the time in my normal aspx pages, why doesn't it work here?
Thanks,
Tom
From a console program:
CODE
class Program { static void Main(string[] args) { DataSet temp = GetDataSet(); DataSet temp2 = new DataSet(); Console.ReadLine(); } public DataSet GetDataSet() { return new DataSet(); } }
The object temp2 gets created fine.
But I get a compiler error on the GetDataSet() method:
An object reference is required for non-static field, method, or property
I do this all the time in my normal aspx pages, why doesn't it work here?
Thanks,
Tom
RE: Static field error
Either do your call outside of a static method, and inside an instance of Program, or change GetDataSet to be static.
CODE --> C#
RE: Static field error
Thanks,
Tom