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


	}

}

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.

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.