正文

c#方法参数2007-10-13 20:12:00

【评论】 【打印】 【字体: 】 本文链接:http://blog.pfan.cn/jixian/30072.html

分享到:

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

namespace __9
{
    class Program
    {
        static void Main(string[] args)
        {
            int a = 3;
            testprimitive(a);
            Console.WriteLine(a);              //3

            ArrayList l = new ArrayList();
            Console.WriteLine(l.Count);            //0
           
            textobjectlist(l);
            Console.WriteLine(l.Count);        //?2
            print(l);

            Console.WriteLine("-------------");
            ArrayList ll = new ArrayList();
            ll.Add("major");
            Console.WriteLine(ll.Count);           //1
            print(ll);
            Console.WriteLine("--------------");
            textobjectlist2(ll);
            Console.WriteLine(ll.Count);       //?1
            print(ll);

            Console.WriteLine("....---------------");
           
            string s = "jack";
            teststring(s);
            Console.WriteLine(s); //jack
        }

        private static void testprimitive(int a)
        {
            a *= 2;
        }
        private static void textobjectlist(ArrayList l)
        {
            l.Add("jumbo");
            l.Add("jumbo2");
        }
        private static void textobjectlist2(ArrayList l)
        {
            l = null;                                            //l 指向null引用,以前的那个对象并没有变
            //l.Add("a");
            //l.Add("b");
        }
        private static void teststring(string s)
        {
            s = "john";
        }

        private static void print(ArrayList l)
        {
            foreach(string s in l)
            {
                Console.WriteLine(s);
            }
        }
    }
}

 

阅读(2098) | 评论(1)


版权声明:编程爱好者网站为此博客服务提供商,如本文牵涉到版权问题,编程爱好者网站不承担相关责任,如有版权问题请直接与本文作者联系解决。谢谢!

评论

loading...
您需要登录后才能评论,请 登录 或者 注册