Created
February 25, 2022 10:21
-
-
Save Havret/196d9b5f3e7b3f9494478b8f80a7dcc7 to your computer and use it in GitHub Desktop.
Arguments - class
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var alice = new Person { Name = "Alice", Age = 17 }; | |
Console.WriteLine($"Inside main => {alice.Name}'s age before function call: {alice.Age}"); | |
IncrementAge(alice); | |
if (alice != null) | |
{ | |
Console.WriteLine($"Inside main => {alice.Name}'s age after function call: {alice.Age}"); | |
} | |
else | |
{ | |
Console.WriteLine("Inside main => Object reference not set to an instance of an object"); | |
} | |
void IncrementAge(Person person) | |
{ | |
Console.WriteLine($"Inside function => {person.Name}'s age before change: {person.Age}"); | |
person.Age += 1; | |
Console.WriteLine($"Inside function => {person.Name}'s age after change: {person.Age}"); | |
person = null; | |
} | |
public class Person | |
{ | |
public string Name { get; set; } | |
public int Age { get; set; } | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment