Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

An object reference is required for the nonstatic field,method

Status
Not open for further replies.

Saturn57

Programmer
Aug 30, 2007
275
CA
How can I stop this error, here is my code and there error occurs where i have decimal.TryParse(....

class EstCalc
{
static void Variables (string[] args)
{

decimal bl; //blank length
decimal bw; //blank width
decimal bp; //blank perifery
decimal pd; //part depth
decimal dq; //die quantity
decimal.TryParse(quantityTB.Text, out dq);
decimal dl; //die length
decimal dw; //die width
decimal ds; //die shut height
decimal d; //density
decimal.TryParse(densityTB.Text, out d);
 
Your void is static. This means it can be used without having an instance of your class, and as such, it must not use any variables or methods that do depend on an instance...

I presume quantityTB and/or densityTB are not static variables?

For example, in your code you could do something like this:

Code:
EstCalc.Variables(new string[] {""});

Without having to do this first:

Code:
EstCalc myEstCalc = new EstCalc();

If I'm right - your possible solutions are:

1. Make the variables that you use in the method static.
2. Make the method non-static.

Kind regards,
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top