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

I need help with C#!!

Reply to Message Icon

Original Message
Name: El-Trucha
Date: March 11, 2005 at 19:01:14 Pacific
Subject: I need help with C#!!
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


Report Offensive Message For Removal

Response Number 1
Name: cupubboy
Date: March 12, 2005 at 15:45:28 Pacific
Subject: I need help with C#!!
Reply: (edit)

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


Report Offensive Follow Up For Removal

Response Number 2
Name: Chi Happens
Date: March 12, 2005 at 20:01:02 Pacific
Subject: I need help with C#!!
Reply: (edit)

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


Report Offensive Follow Up For Removal

Response Number 3
Name: El-Trucha
Date: March 18, 2005 at 12:54:21 Pacific
Subject: I need help with C#!!
Reply: (edit)

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


Report Offensive Follow Up For Removal







Use following form to reply to current message:

   Name: From My Computing.Net Settings
 E-Mail: From My Computing.Net Settings

Subject: I need help with C#!!

Comments:

 


  Homepage URL (*): 
Homepage Title (*): 
         Image URL: 
 
Data Recovery Software