源码网商城,靠谱的源码在线交易网站 我的订单 购物车 帮助

源码网商城

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

  • 时间:2022-07-23 11:47 编辑: 来源: 阅读:
  • 扫一扫,手机访问
摘要:深入Ref,Out的理解及其使用
[u]复制代码[/u] 代码如下:
    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);             }         } 
  • 全部评论(0)
联系客服
客服电话:
400-000-3129
微信版

扫一扫进微信版
返回顶部