小小飞鹰

     中国人缺少的是步骤,太急。练太极!
  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

[练手7]传值和传引用区别

Posted on 2008-11-26 11:24  小小飞鹰  阅读(247)  评论(0编辑  收藏  举报

 演示代码
    class ReferClass
    {
        public int intValue;
    }
    class 值和引用的区别
    {
        public static void GetValue(int intValue)
        {
            intValue = 10;
        }
        public static void GetReference(ReferClass referClass)
        {
            referClass.intValue = 10;
        }
    }

测试代码

        static void Main(string[] args)
        {
            //值和引用的区别
            int intNewValue = 0;

            值和引用的区别.GetValue(intNewValue);
            Console.WriteLine("值和引用的区别演示传值后是:" + intNewValue);

            ReferClass refer = new ReferClass();
            refer.intValue = 0;
            值和引用的区别.GetReference(refer);

            Console.WriteLine("值和引用的区别演示传引用后是:" + refer.intValue);

      }