Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Foo
- {
- public int a = 10;
- }
- // out -> more or less like ref
- // difference = we don't need to initialize the object we pass beforehand
- static void getNameSurname(out string name, out string surname)
- {
- name = Console.ReadLine();
- surname = Console.ReadLine();
- }
- // ref -> passes the reference so we modify the object itself
- static void PutAZero(ref Foo number)
- {
- number = null;
- }
- static void Run(string[] args)
- {
- Foo x = new Foo();
- PutAZero(ref x);
- //Console.WriteLine(x.a); // Throws exception bc null
- string n, s;
- getNameSurname(out n, out s); // With ref -> need to initialize, with out -> not
- Console.WriteLine("Name: " + n);
- Console.WriteLine("Surname: " + s);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement