Change the object referenced by the myHouse object reference to the object referenced by yourHouse : Object Reference « Class « C# / CSharp Tutorial

C# / CSharp Tutorial
1. Language Basics
2. Data Type
3. Operator
4. Statement
5. String
6. struct
7. Class
8. Operator Overload
9. delegate
10. Attribute
11. Data Structure
12. Assembly
13. Date Time
14. Development
15. File Directory Stream
16. Preprocessing Directives
17. Regular Expression
18. Generic
19. Reflection
20. Thread
21. I18N Internationalization
22. GUI Windows Forms
23. 2D
24. Design Patterns
25. Windows
26. XML
27. ADO.Net
28. Network
29. Directory Services
30. Security
31. unsafe
Microsoft Office Word 2007 Tutorial
Java
Java Tutorial
Java Source Code / Java Documentation
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
C# / C Sharp
ASP.Net
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
PHP
Python
SQL Server / T-SQL
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
C# / CSharp Tutorial » Class » Object Reference 
7. 3. 7. Change the object referenced by the myHouse object reference to the object referenced by yourHouse
 

class House
{
  public string make;
  public string model;
  public string color;
  public int yearBuilt;

  public void Start()
  {
    System.Console.WriteLine(model + " started");
  }

  public void Stop()
  {
    System.Console.WriteLine(model + " stopped");
  }

}

class MainClass
{

  public static void Main()
  {
    
    House myHouse;

    myHouse = new House();

    myHouse.Start();
    myHouse.Stop();

    
    House yourHouse = new House();
    yourHouse.make = "AAA";
    yourHouse.model = "VVV";
    yourHouse.color = "red";
    yourHouse.yearBuilt = 2000;
    System.Console.WriteLine("yourHouse is a " + yourHouse.model);

    
    System.Console.WriteLine("Assigning yourHouse to myHouse");
    myHouse = yourHouse;
    System.Console.WriteLine("myHouse details:");
    System.Console.WriteLine("myHouse.make = " + myHouse.make);
    System.Console.WriteLine("myHouse.model = " + myHouse.model);
    System.Console.WriteLine("myHouse.color = " + myHouse.color);
    System.Console.WriteLine("myHouse.yearBuilt = " + myHouse.yearBuilt);

  }
}

        
 started
 stopped
yourHouse is a VVV
Assigning yourHouse to myHouse
myHouse details:
myHouse.make = AAA
myHouse.model = VVV
myHouse.color = red
myHouse.yearBuilt = 2000
  
7. 3. Object Reference
7. 3. 1. Declare class fields and methods
7. 3. 2. Declare a House object reference named myHouse
7. 3. 3. Creating a House object and assigning its memory location to myHouse
7. 3. 4. Assign values to the House object's fields using object renerence
7. 3. 5. Display the field values using object reference
7. 3. 6. Declare another House object reference and create another House object
7. 3. 7. Change the object referenced by the myHouse object reference to the object referenced by yourHouse
7. 3. 8. Reference type equals: complex number
7. 3. 9. Reference equals
7. 3. 10. Reference a static member function without using the class name
7. 3. 11. Overridden Equals()
7. 3. 12. Reference an object by interface and class
7. 3. 13. Pass reference type variable without 'out' and 'ref'
7. 3. 14. Use interface as reference
7. 3. 15. Reference one object by multiple interfaces
w_w___w__._ja___va___2_s_.___c__o__m___ | Contact Us
Copyright 2003 - 08 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.