Skip to content

Instantly share code, notes, and snippets.

@Havret
Created February 25, 2022 10:21
Show Gist options
  • Save Havret/196d9b5f3e7b3f9494478b8f80a7dcc7 to your computer and use it in GitHub Desktop.
Save Havret/196d9b5f3e7b3f9494478b8f80a7dcc7 to your computer and use it in GitHub Desktop.
Arguments - class
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