如何使實體參數爲私有?如何使實體參數爲私有?
現在,實體參數就像全局變量一樣。
protected void ButtonSubmit_Click(object sender, EventArgs e)
{
var poProductDefault = new ProductEntity();
poProductDefault.CGROUP1 = "5";
string Name = "123456";
DoSomethingEntity1(Name, poProductDefault);
Label1.Text = Name;
Label1.Text = poProductDefault.CGROUP1; //Why "2000" ???? Is not "5"
}
private void DoSomethingEntity1(string Name, ProductEntity toProductDef)
{
Name = "ABC Changed";
toProductDef.CGROUP1 = "2000";
}
爲什麼「2000」?因爲您更改了「DoSomethingEntity1」功能中的值。 – Kinetic
閱讀有關c#中對象的更多信息,並嘗試檢查其行爲,C#中的對象通過引用傳遞,這意味着傳遞的地址指向內存中的同一對象。 'ProductEntity'是一個引用類型,而不是一個值類型。花時間閱讀 – Sherlock
你是什麼意思?方法有參數,實體沒有。 –