首页 > Windows开发 > 详细

C#中引用(ref关键字)参数

时间:2015-03-01 20:53:28      阅读:290      评论:0      收藏:0      [点我收藏+]
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace 函数的参数
{

    class Program
    {
        static void mm(ref int x, ref int y)
        {
            Console.WriteLine("传入函数mm的参数为:x = {0},y = {1}", x, y);
            //以下这三句代码为:交换两个参数的值
            int temp = x;
            x = y;
            y = temp;
            Console.WriteLine("在执行函数mm后输出的参数值为:x = {0},y = {1}", x, y);
        }
        static void Main(string[] args)
        {
            int i = 21, j = 34;
            Console.WriteLine("在Main方法中调用mm函数传入两个参数:i = {0},j = {1}", i, j);
            mm(ref i, ref j);
            Console.WriteLine("在Main中执行完mm函数之后:i = {0},j = {1}", i, j);
            Console.ReadKey();
        }
    }
}

技术分享

C#中引用(ref关键字)参数

原文:http://www.cnblogs.com/blogofwyl/p/4307524.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!