/* 嗨,我正在尝试在 Visual Studio 上制作我的第一个 c# 应用程序。我在 main 中创建了一个类和该类的一个实例,我只是想在表单上的单击事件中查询该实例的成员,但它告诉我实例名称在当前上下文中不存在。任何帮助将不胜感激这是我的代码。*/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;
namespace WindowsFormsApplication10
{
public class character // this is my class
{
public bool hair_black;
}
static class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());
character deviljin = new character(); // instance of my class
deviljin.hair_black = true; // initiating a member of the instance
}
}
}
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace WindowsFormsApplication10
{
public partial class Form1 : Form
{
int cs1 = 0,cs2=0;
public Form1()
{
InitializeComponent();
public void pictureBox1_Click(object sender, EventArgs e)
{
flowLayoutPanel1.Visible = true;
if (deviljin.hair_black == true) // trying to access instance member
{ // but getting deviljin does not
// exist in the current context
pictureBox28.Visible = false;
}
}
}
}