您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息

C# 中数组类型的引用/ref 参数是什么?

2024/4/30 14:50:56发布16次查看
使用 ref 关键字声明引用参数。引用参数是对变量内存位置的引用。当您通过引用传递参数时,与值参数不同,不会为这些参数创建新的存储位置。
声明引用参数 -
public void swap(ref int x, ref int y) {}
声明数组类型的 ref 参数 -
static void display(ref int[] myarr)
以下示例展示了如何在 c# 中使用数组类型的 ref 参数 -
class testref { static void display(ref int[] myarr) { if (myarr == null) { myarr = new int[10]; } myarr[0] = 345; myarr[1] = 755; myarr[2] = 231; } static void main() { int[] arr = { 98, 12, 65, 45, 90, 34, 77 }; display(ref arr); for (int i = 0; i < arr.length; i++) { system.console.write(arr[i] + " "); } system.console.readkey(); }}
以上就是c# 中数组类型的引用/ref 参数是什么?的详细内容。
该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录 Product