Hi,
In button1_Click(), how can I get "aValue" from Main(), somthing like:
static class Program
{
[STAThread]
static void Main()
{
int aValue = 1;
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDe...
Application.Run(new Form1());
}
}
public partial class Form1 : Form
{
private void button1_Click(object sender, EventArgs e)
{
Console.WriteLine("aValue = " + aValue);
}
}
I will appreciated for your code, I am a beginner.
Loading

VulpesRank #55 · 29.2K reputationPosted Dec 7, 2013, 7:02 AM EST
Dave48 reputationPosted Dec 7, 2013, 7:34 AM EST
I tried and got error in Form1 button1_Click():
The name 'aValue' does not exist in the current context
VulpesRank #55 · 29.2K reputationPosted Dec 7, 2013, 8:00 AM EST
Dave48 reputationPosted Dec 7, 2013, 8:21 AM EST
One more thing:
Why I can also use Console.Writeline() in
private void button1_Click(object sender, EventArgs e)?
VulpesRank #55 · 29.2K reputationPosted Dec 7, 2013, 9:08 AM EST
However, if you right click on the project name in Solution Explorer, select Properties from the dropdown and then, under the Application tab, change the output type to Console application, a console will be attached and such statements will work fine.
Dave48 reputationPosted Dec 7, 2013, 10:34 AM EST