params的练习


        public static void DisplayString(params string[] strNames)//好像对于本例来说去掉params效果也一样,但是加上params后直接使用传递的参数列表
        {
            foreach (var item in strNames)
            {
                Console.WriteLine(item.ToString());
            }
        }


        public static void ParamsTest( string[] names)
        {
            for (int i = 0; i < names.Length;i++ )
            {
                Console.WriteLine(names[i]);
            }
        }
   
        static void Main(string[] args)
        {
            Type typePepper = Type.GetType("ReflectionExam.Pepper");
            object[] conParams = new object[] { "小辣椒", "白色" };

            object pepperObject = Activator.CreateInstance(typePepper, conParams);
           


          //  DisplayString(conParams);
            string[] pepperNames1 = new String[3] { "gan", "quan", "fu" };
            string[] pepperNames2 = new String[4] { "gan2", "quan2", "fu2","ganq2" };
            DisplayString(pepperNames1);
            Console.WriteLine("@@@@@@@@@@@@@@@@@@@@");
            DisplayString(pepperNames2);

            Console.WriteLine("@@@@@@@@@@@@@@@@@@@@");
            DisplayString("sfs", "afasfa", "fasfsa");


            Console.WriteLine("finished");
            Console.Read();
         
        }
    }

posted @ 2013-03-28 18:53  Predator  阅读(113)  评论(0编辑  收藏  举报