如何将实体参数设为私有?

时间:2016-09-06 23:33:51

标签: c# entity-framework parameters entity

如何将实体参数设为私有?

现在,实体参数就像全局一样。

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";
}

1 个答案:

答案 0 :(得分:0)

C#对象通过引用传递,因此您的代码实际上将对象poProductDefault传递给方法DoSomethingEntity1()。 要在DoSomethingEntity1()方法中创建实体参数(我猜你的意思是说属性)private,你可以在里面创建另一个ProductEntity对象 DoSomethingEntity1()并从poProductDefault对象赋值并指定CGROUP1 = 2000.从DoSomethingEntity1()返回此另一个ProductEntity对象,并从此对象使用CGROUP1值分配给Label1.Text

相关问题