1.前言
傳遞參數,不需要返回值,對懶人很舒服喲,缺點是不好定位數據
2.操作
using System; namespace ConsoleApp1.letVlaueGo { public class DoValue { public static void Main(string[] args) { //初始值 int a = 1; int b = 2; /* * main方法不允許使用this調用同級頁面的方法,只有在方法中才可以 * */ DoValue d = new DoValue(); //按引用內存地址傳參 d.na(ref a, ref b); //可直接打印,不需要在這里賦值,因為內存地址的數據變了 Console.WriteLine(a); Console.WriteLine(b); // // //按輸出傳遞參數 d.getValus(out a, out b); Console.WriteLine(a); Console.WriteLine(b); } //按引用內存地址傳參,前提:參數必須是非常量,即不允許加const關鍵字 private void na(ref int a, ref int b) { int temp; temp = a; a = b; b = temp; } //按輸出傳遞參數 private void getValus(out int a, out int b) { a = 100; b = 200; } } }
3.測試
控制台打印

