In a C# 2008 solution file, there are 4 project files that interact with each other. While I am in the project file called 'app1', I want to be able to obtain the values in another project file called 'samples'.
When I am in debug looking at the locals window, I can see the value I want to obtain is in the following location: samples.PackageMetadata.SubCustomerNumber.
However I am getting the error: An object reference is required for the non-static field, method, or property 'samples.PackageMetadata.SubCustomerNumber.get'.
Thus can you show me code and tell me what I need to do so that I can obtain the 'SubCustomerNumber' value I need for an error message?
Loading
VulpesPosted Jan 8, 2013, 12:59 PM
Riddhi ValechaPosted Jan 9, 2013, 2:12 AM
If you have static methods, then you call those method as - classname.Methodname.
Eg.
Class C1
{
public static string Method1()
{
return "Hello World";
}
}
Main()
{
string r =C1.Method1();
}
-----------------
For non static methods, we use the new keyword and call methods.
Class C1
{
public string Method1()
{
return "Hello World";
}
}
Main()
{
C1 c = new C1();
string s = c.Method1();
}
Santhosh Kumar JayaramanPosted Jan 8, 2013, 12:03 PM
http://stackoverflow.com/questions/498400/an-object-reference-is-required-for-the-nonstatic-field-method-or-property-wi
It is well explained
dcPosted Jan 8, 2013, 11:49 AM
Sandeep Singh ShekhawatPosted Jan 8, 2013, 11:38 AM
As per my understanding that you are calling a non static property in static method so you need to create the static property.
Because static method always use static field or properties. We can't use non-static properties in static method.
pls post your code in which you are getting error and where you are calling it.
Thanks
Sandeep