private static void Main(string[] args) { #region Struct TheStruct st = new TheStruct(); st.x = 1; StructTaker(st); Console.WriteLine(st.x); // output : 1 #endregion Struct #region Class TheClass cs = new TheClass(); cs.x = 1; ClassTaker(cs); Console.WriteLine(cs.x); // output : 5 #endregion Class }
/// <summary> /// 改變傳遞過來結構的值 /// </summary> /// <param name="s">傳遞結構</param> private static void StructTaker(TheStruct s) { s.x = 5; }