Please support our C# advertiser: Programming Forums
Views: 1177 | Replies: 2
![]() |
•
•
Join Date: Apr 2006
Posts: 5
Reputation:
Rep Power: 0
Solved Threads: 0
:-| Why won't this code work?
using System;
using System.Windows.Forms;
namespace Practice
{
class Practice
{
public static void Main()
{
// declare and assign a string variable called human
string human;
human = "Walking & talking life";
// declare and assign an int variable called mind
int mind;
mind = 100;
// Print the value of the variables to the console
Console.WriteLine(mind);
Console.WriteLine(human);
}
}
class Continued
{
public static void notMain()
{
MessageBox.Show(human);
MessageBox.Show(mind);
}
}
} Last edited by alc6379 : Apr 19th, 2006 at 1:46 pm. Reason: added Code tags.
•
•
Join Date: Dec 2003
Location: Nashville, TN
Posts: 2,336
Reputation:
Rep Power: 11
Solved Threads: 102
Did you want the class Continued to inherit from the class Practice, or did you just want Continued to create a new object of type Practice?
I'm confused.
Heck, if you even wanted to do either of those, you declared the variables inside of your Method. In order to use them in another class, or as the property of a newly instantiated Practice object, you'd want to put them in the root of the Class, as public variables. Either that, or make them private, and provide accessors for the fields using public Properties.
If you rewrite it to do that, maybe we could help more.
I'm confused.

Heck, if you even wanted to do either of those, you declared the variables inside of your Method. In order to use them in another class, or as the property of a newly instantiated Practice object, you'd want to put them in the root of the Class, as public variables. Either that, or make them private, and provide accessors for the fields using public Properties.
If you rewrite it to do that, maybe we could help more.
Alex Cavnar, aka alc6379
![]() |
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)






Linear Mode