现在的位置: 首页 > 综合 > 正文

值和引用

2012年03月10日 ⁄ 综合 ⁄ 共 486字 ⁄ 字号 评论关闭

using System;
using System.Collections.Generic;
using System.Text;

namespace 值和引用
{
    class Program
    {
        public void swap(ref int x,ref int y)
        {
            int wy = x;
            x = y;
            y = wy;
        }

        static void Main(string[] args)
        {
            int a = 100, b = 200;
            Console.WriteLine("之前:a:{0},b:{1}", a, b);
           Program loves=new Program ();
           loves.swap(ref a,ref b);
            Console.WriteLine("之后:a:{0},b:{1}", a, b);
            Console.Read();
          
        }
    }
}

抱歉!评论已关闭.