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

VulpesRank #55 · 29.2K reputationPosted Jan 8, 2013, 7:59 AM EST
Sandeep Singh ShekhawatRank #147 · 15.6K reputationPosted Jan 8, 2013, 6:38 AM EST
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
dcRank #2,247 · 627 reputationPosted Jan 8, 2013, 6:49 AM EST
Santhosh Kumar JayaramanRank #563 · 4.3K reputationPosted Jan 8, 2013, 7:03 AM EST
http://stackoverflow.com/questions/498400/an-object-reference-is-required-for-the-nonstatic-field-method-or-property-wi
It is well explained
Riddhi ValechaRank #794 · 2.9K reputationPosted Jan 8, 2013, 9:12 PM EST
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();
}