C
C#novice
Like my name says I am a total novice at C#. I am trying to following
examples in a book that I have but unfortunately they do not provide you with
code for the whole project. Up till now I could figure out what is causing
my problems but now I am stuck. I added in the books code into a Windows
Application:
using System;
using System.Collections.Generic;
using System.Windows.Forms;
namespace WindowsApplication1
{
class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
}
private void btnClickMe_Click(object sender, System.EventArgs e)
{
string msg = " ";
if (txtBeatle.Text == "John")
goto john;
if (txtBeatle.text == "Ringo")
goto ringo;
goto done;
john:
msg = "I like John best, too!";
goto done;
ringo:
msg = "Are you a drummer?";
goto done;
done:
if (msg != " ")
MessageBox.Show(msg, "Beatle choice",
MessageBoxButtons.OK);
}
}
}
When I try to compile the code it displays an error ‘txtBeatle’ does not
exist in the current context. txtBeatle does not look like a variable
because it has .Text behind it. Could somebody be so kind as to tell what I
need to do to fix the problem.
examples in a book that I have but unfortunately they do not provide you with
code for the whole project. Up till now I could figure out what is causing
my problems but now I am stuck. I added in the books code into a Windows
Application:
using System;
using System.Collections.Generic;
using System.Windows.Forms;
namespace WindowsApplication1
{
class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
}
private void btnClickMe_Click(object sender, System.EventArgs e)
{
string msg = " ";
if (txtBeatle.Text == "John")
goto john;
if (txtBeatle.text == "Ringo")
goto ringo;
goto done;
john:
msg = "I like John best, too!";
goto done;
ringo:
msg = "Are you a drummer?";
goto done;
done:
if (msg != " ")
MessageBox.Show(msg, "Beatle choice",
MessageBoxButtons.OK);
}
}
}
When I try to compile the code it displays an error ‘txtBeatle’ does not
exist in the current context. txtBeatle does not look like a variable
because it has .Text behind it. Could somebody be so kind as to tell what I
need to do to fix the problem.