Click here to Skip to main content
15,913,722 members
Please Sign up or sign in to vote.
3.50/5 (2 votes)
Since a value of a class obtains and that it shows it in other one. For example:
I have a class called Product and there I have a Field called Price. In another class called Transaction I want that the price appears for the selected product.
I am grateful for any help.

---EDIT kschuler: removed code block
Posted
Updated 9-Mar-11 6:35am
v2
Comments
rajivpande86 9-Mar-11 12:39pm    
How are you identifying the different products in this Product class?Some identifier or sumthing else, because from your ? it is not clear.
Albin Abel 9-Mar-11 14:27pm    
Still I am not clear with the question

1 solution

How is your Transaction class set up?

I would assume it allows for at least one product...is that correct? As in

C#
class Transaction
{
  private Product _purchasedProduct;
  public Product PurchasedProduct
  {
    get
    {
      return this._purchasedProduct;
    }
    set
    {
      this._purchasedProduct = value;
    }
  }
}


If that's the case, then you could just do:
C#
Transaction newTransaction = new Transaction();
newTransaction.PurchasedProduct = new Banana();
Console.WriteLine(newTransaction.PurchasedProduct.Price.ToString());
 
Share this answer
 
Comments
Monjurul Habib 9-Mar-11 13:14pm    
that would be my answer too, my 5+.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900