repl.it
@kironroy/

refvsvalue2

C#

No description

fork
loading
Files
  • main.cs
  • main.exe
main.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
using System;

public class Person 
{
  public int Age; // field
} 

class MainClass {
  public static void Main (string[] args) {
    var number = 1; // int, value type
    Increment(number);
    Console.WriteLine(number);

   Console.WriteLine(); // breakline

   var numberTwo = 22;
   Increment(numberTwo);

   
   

  Console.WriteLine(); // breakline

    var person = new Person() {Age = 110};
    MakeOld(person);
    Console.WriteLine(person.Age);
  }

  public static void Increment(int number)
  {
    number += 10;
    Console.WriteLine(number);
  }

  public static void MakeOld(Person person) // Person class reference type
  {
    person.Age += 15;
  }
}