using System; using System.Collections.Concurrent; using System.Collections.Generic; using System.Diagnostics; using System.Linq; using System.Text; using System.Threading; using System.Threading.Tasks; namespace Test { class Program { static void Main(string[] args) { int a=0; //ref传参时必须赋值,但方法体内可不不赋值 RefMethod(ref a); Console.WriteLine(a); //out传参时可以不赋值,但方法体内必须赋值 OutMethod(out a); Console.WriteLine(a); } static void RefMethod(ref int a) { a = 20; } static void OutMethod(out int a) { a = 30; } } }