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);
		}


	}

}
3
Contributors
2
Replies
3
Views
11 Years
Discussion Span
Last Post by alc6379
0

well, to start off with the variables human and mind are neither declared nor instantiated in the Continued class, so this isn't even going to compile.

0

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. :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.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.