全て。
私はC#の初心者です。これは非常に人気のある質問です。しかし、私は理解していませんでした。間違いがあることは知っていますが、どこですか?たとえば、コード Form1 の最初の部分にはプライベート変数 test が含まれています。Form2 でこの変数の値を取得する必要があります。エラーはどこにありますか?
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 WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
string test = "test this point";
Form2 dlg = new Form2();
dlg.test = test;
dlg.Show();
}
}
}
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 WindowsFormsApplication1
{
public partial class Form2 : Form
{
public string test { get; set; }
public Form2()
{
InitializeComponent();
label1.Text = test;
}
}
}