using System; class MyClass { public int Val = 20; } class MainClass { static void MyMethod(MyClass myObject, int intValue) { myObject.Val = myObject.Val + 5; intValue = intValue + 5; } static void Main() { MyClass myObject = new MyClass(); int intValue = 10; Console.WriteLine("Before -- myObject.Val: {0}, intValue: {1}", myObject.Val, intValue); MyMethod(myObject, intValue); Console.WriteLine("After -- myObject.Val: {0}, intValue: {1}", myObject.Val, intValue); } }
Before -- myObject.Val: 20, intValue: 10 After -- myObject.Val: 25, intValue: 10
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 | |||
7.3.16. | Class comparison |