Advertisement

05.01.2008 at 07:39AM PDT, ID: 23368663
[x]
Attachment Details

C# console to windiws message

Asked by 9apit in Microsoft Visual C#.Net, C# Programming Language

Tags: C#, console to Windows

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
[+][-]05.01.2008 at 07:50AM PDT, ID: 21479155

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]05.01.2008 at 08:07AM PDT, ID: 21479314

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]05.01.2008 at 08:34AM PDT, ID: 21479604

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]05.01.2008 at 09:10AM PDT, ID: 21479962

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]05.01.2008 at 11:09AM PDT, ID: 21481034

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]05.01.2008 at 12:08PM PDT, ID: 21481591

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]05.01.2008 at 12:28PM PDT, ID: 21481796

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zones: Microsoft Visual C#.Net, C# Programming Language
Tags: C#, console to Windows
Sign Up Now!
Solution Provided By: pragmatistMS
Participating Experts: 1
Solution Grade: A
 
 
 
Loading Advertisement...
20080716-EE-VQP-32 / EE_QW_2_20070628