1

I'm not able to retrieve values using set nor get. Can you tell where I made mistake?

form1.cs// ui tier

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

class2.cs // business tier

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 // business tier

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

can anyone help....

Jana
  • 49
  • 3
  • 8
  • 1
    In form3.cs, you have a *different* `bb obj`, which has a *different* `_Pur_Net_Total_Amount`. – crashmstr Dec 12 '13 at 13:38
  • possible duplicate of [how to pass variable values between two class in different projects](http://stackoverflow.com/questions/20545888/how-to-pass-variable-values-between-two-class-in-different-projects) – albusshin Dec 12 '13 at 14:34

2 Answers2

4

Because you created object obj and assign a string to its property in form1.cs, later you are creating another object with the same name in form3.cs, that object has no knowledge of your previous object (created in form1).

Having same name in two different places would not get you the same object.

You can pass the object to form3 from form1, see Passing Values Between Windows Forms c#

Community
  • 1
  • 1
Habib
  • 219,104
  • 29
  • 407
  • 436
  • @Jana, changing the object name would not do anything, You have too look into the way for passing values between multiple forms. look at the linked question in the answer. – Habib Dec 12 '13 at 13:58
2

You are creating a new object in the lower code. You do bb obj = new bb();, this is a new instance. It is not the same instance as the above one where you set the property.

odyss-jii
  • 2,619
  • 15
  • 21