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 WindowsFormsApplication9 { public partial class Form1 : Form { public Form1() { InitializeComponent(); BindSCT(TheSCT); } CSCT TheSCT = new CSCT(); public class CSCT { public string NO { get; set; } } private void BindSCT(CSCT sct) { BindingSource bs = new BindingSource(); bs.DataSource = sct; txtNO.DataBindings.Add("Text", bs, "NO", false, DataSourceUpdateMode.OnPropertyChanged); } private void btnSave_Click(object sender, EventArgs e) { MessageBox.Show(TheSCT.NO); } } }
在这一句里, bs是复制一份sct, 还是指向sct?
bs.DataSource = sct;
TheSCT.NO=sct.NO;
txtNO.DataBindings.Add("Text", bs, "NO");
class InstanceA : ICloneable
{}
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;namespace WindowsFormsApplication9
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent(); BindSCT(TheSCT);
} CSCT TheSCT = new CSCT();
public class CSCT
{
public string NO
{
get;
set;
}
} private void BindSCT(CSCT sct)
{
BindingSource bs = new BindingSource();
bs.DataSource = sct;
txtNO.DataBindings.Add("Text", bs, "NO", false, DataSourceUpdateMode.OnPropertyChanged);
} private void btnSave_Click(object sender, EventArgs e)
{
MessageBox.Show(TheSCT.NO);
}
}
}