Getting an error : An object reference is required for the non-static field, method, or property in C#
This error normally occurs when anyone tries to call an instance method, but without specifying an instance.
I will make it easier for you by giving an example.
In the code you must have declared function
and you must be trying to call the function using
This error normally occurs when anyone tries to call an instance method, but without specifying an instance.
I will make it easier for you by giving an example.
In the code you must have declared function
public void CallMe()
{
. . .
return someString;
}
and you must be trying to call the function using
string str = CallMe();
Solution:
You can use static to overcome this problem.
public static void CallMe()
{
. . .
return someString;
}
Hope this helps.
0 comments:
Post a Comment