Ref Out 深入Ref,Out的理解及其使用

软件发布|下载排行|最新软件

当前位置:首页IT学院IT技术

Ref Out 深入Ref,Out的理解及其使用

  2021-03-18 我要评论
想了解深入Ref,Out的理解及其使用的相关内容吗,在本文为您仔细讲解Ref Out的相关知识和一些Code实例,欢迎阅读和指正,我们先划重点:c#,Ref,Out,下面大家一起来学习吧。
复制代码 代码如下:

    class Program 
       { 
           //使用out后必须对变量赋值 
           public void TestOut(out int x, out int y) 
           { 
               x = 1; 
               y = 2; 
           } 
           //此时传进来的值分别为x1:10,y1:11,输出之后的x1的值为2 

           public void TestRef(ref int x, ref int y) 
           { 
               //引用剪剪那句话传进来的是猪,出来的可能是头牛(很精辟!) 
               x = 2; 

           } 
           static void Main(string[] args) 
           { 
               int x; 
               int y; 
               Program P1 = new Program(); 
               P1.TestOut(out x,out y); 
               Console.WriteLine("x={0},y={1}", x, y); 
               //在使用之前ref必须对变量赋值 
               int x1 = 10; 
               int Y1 = 11; 
               P1.TestRef(ref x1,ref Y1); 
               Console.WriteLine("x1={0},y1={1}", x1, Y1); 
           } 
       } 

Copyright 2022 版权所有 软件发布 访问手机版

声明:所有软件和文章来自软件开发商或者作者 如有异议 请与本站联系 联系我们