Good morning expert,
Working with a simple C# program that writes three words out to console session to learn about
instance variables and class access. Program has two files Main.cs and Apple.cs, listed below
Trying to rewrite the console application as a windows application that does the display as a message box with two files called AppleMainW.cs and AppleW.cs, also listed below. Getting error message from Visual Studio 2003:
'The name 'variety' does not exist in the class or namespace 'Apple.AppleMain' How can I get the variety variable to be seen by the Main() method?
Thanks.
Allen in Dallas
++++Console applcation Apple.cs +++++
using System;
namespace Apple
{
public class Apple
{
private string variety = "";
public Apple(string appleVariety)
{
this.variety = appleVariety;
}
public void outputVariety()
{
Console.WriteLine(variety)
;
//System.Console.WriteLine
(variety);
}
}
}
++++Console applcation Main.cs +++++
using System;
namespace Apple
{
/// <summary>
/// Summary description for Class1.
/// </summary>
class AppleMain
{
static void Main()
{
Apple mac = new Apple("Macintosh");
Apple gra = new Apple("Granny Smith");
Apple cor = new Apple("Cortland");
mac.outputVariety();
gra.outputVariety();
cor.outputVariety();
}
}
}
++++Windows applcation AppleW.cs +++++
using System;
namespace Apple
{
public class Apple
{
private string variety = "";
public Apple(string appleVariety)
{
this.variety = appleVariety;
}
public void outputVariety()
{
// Console.WriteLine(variety)
;
//System.Console.WriteLine
(variety);
}
}
}
++++Windows applcation AppleMainW.cs +++++
using System;
using System.Windows.Forms;
namespace Apple
{
class AppleMain
{
static void Main( string[] args )
{
Apple mac = new Apple("Macintosh");
Apple gra = new Apple("Granny Smith");
Apple cor = new Apple("Cortland");
mac.outputVariety();
gra.outputVariety();
cor.outputVariety();
MessageBox.Show( "Apple varietys are " + variety,
"Display apple varietys",
MessageBoxButtons.OK,
MessageBoxIcon.Information
);
} // end Main
} // end class AppleMain
} // end namespace Apple
Start Free Trial