gpt4 book ai didi

c# - 我无法在 2tier 中使用 set get 属性检索值

转载 作者:太空宇宙 更新时间:2023-11-03 19:11:06 28 4
gpt4 key购买 nike

我无法使用 setget 检索值。你能告诉我哪里出错了吗?

form1.cs//ui层

 bb obj= new bb();
obj._Pur_Net_Total_Amount="fun";
method();

class2.cs//业务层

class bb()  
{
string Net_Total_Amount = string.Empty;
public string _Pur_Net_Total_Amount
{
get { return Net_Total_Amount; }
set { Net_Total_Amount = value; }
}
}

form3.cs//业务层

    bb obj = new bb();
textbox1.text=obj._Pur_Net_Total_Amount;//here i'm not getting "fun" string value

谁能帮忙....

最佳答案

因为您在 form1.cs 中创建了对象 obj 并为其属性分配了一个字符串,稍后您将在 form3 中创建另一个具有相同名称的对象。 cs,该对象不知道您之前的对象(在 form1 中创建)

在两个不同的地方有相同的名字不会让你得到相同的对象。

您可以将对象从form1 传递到form3,参见Passing Values Between Windows Forms c#

关于c# - 我无法在 2tier 中使用 set get 属性检索值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20545004/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com