Computing.Net > Forums > Programming > I need help with C#!!

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

I need help with C#!!

Reply to Message Icon

Name: El-Trucha
Date: March 11, 2005 at 19:01:14 Pacific
OS: Windows XP SP2
CPU/Ram: 2.8 GHz/448 MB
Comment:

Hello every1!! :D
OK...here are some lines of code and their errors...I'd really appreciate it if somebody explained to me WHY these errors are happening:

This is at Test2.Form1:
public double totalPrice = 0;
Error:Invalid expression term 'public'

This is on another namespace:

Form1 oForm1 = new Form1();
this.total.Text = "Total: " + oForm1.totalPrice.ToString("C");

Error: 'Test2.Form1' does not contain a definition for 'totalPrice'

I know both problems are related to each other...what's the problem?? :(
Thanx!! ;)

El-Trucha
http://www.truchasoft.tk
ftp://tsfc.homeftp.net
hotline://tsfc.ath.cx



Sponsored Link
Ads by Google

Response Number 1
Name: cupubboy
Date: March 12, 2005 at 15:45:28 Pacific
Reply:

Hi .. can you show like more of the class in wich for example you use totalPrice?
for example if you have a non-static Method Test() and a variable in it called var .. it would make no sense to flag the var variable as being public as it cannot be seen from outside the method .. it is a local variable.

I'm sorry If I don;t make much sense.. english is not my native language.. so if you still need help please post some more of your code (around the totalPrice var).

My guess is you're trying to declare a local variable as being public ... and if this is what you are doing then I suggest declaring the variable outside the method.. in the class


0

Response Number 2
Name: Chi Happens
Date: March 12, 2005 at 20:01:02 Pacific
Reply:

right that error occurs when you do something like this:

public void myfunct()
{
public double totalPrice = 0;

}

you can't do that, you have to do this:
public void myfunct()
{
double totalPrice = 0;
}

if you want to use this as public, then you need to declare it ouside of all functions like so:

public class myclass
{
public double totalPrice = 0;
public myclass()
{
}

}

hope this helps,
Chi

They mostly come at night...mostly


0

Response Number 3
Name: El-Trucha
Date: March 18, 2005 at 12:54:21 Pacific
Reply:

Fixed!! I did something like this:


public class MyClass
{
double totalPrice = 0;
public static double GetPrice()
{
return totalPrice;
}
public static void SetPrice(double num)
{
totalPrice = num;
}
}

Thanx everybody anyways!! ;)

El-Trucha
http://www.truchasoft.tk
ftp://tsfc.homeftp.net
hotline://tsfc.ath.cx


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: I need help with C#!!

Need help with C++? www.computing.net/answers/programming/need-help-with-c/4642.html

I need help in c plzzz www.computing.net/answers/programming/i-need-help-in-c-plzzz/529.html

help with C www.computing.net/answers/programming/help-with-c-/7817.html