ref — must be initialized before passing. out — must be assigned inside method.
ref parameter:
1void Increment(ref int x) {2 x++; // Read and modify3}45int a = 5;6Increment(ref a); // a must be initialized7Console.WriteLine(a); // 6
out parameter:
1bool TryParse(string s, out int result) {2 result = int.Parse(s); // Must assign3 return true;4}56int number; // No initialization needed7bool success = TryParse("123", out number);
Key differences:
Use cases: