码迷,mamicode.com
首页 > 编程语言 > 详细

参数数组params

时间:2014-11-28 20:09:08      阅读:263      评论:0      收藏:0      [点我收藏+]

标签:style   blog   http   io   ar   color   sp   for   on   

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace nange_1
{
    class A
    {
        public void listint(params int[] array)
        {
            for (int i = 0; i < array.Length; i++)
            { array[i] = array[i] * 10;
Console.WriteLine("{0}", array[i]);
} } }
class Program { static void Main(string[] args) { int a = 1, b = 2, c = 3; A objA = new A(); objA.listint(a, b, c); Console.WriteLine(a + " " + b + " " + c); Console.ReadLine(); } } }
bubuko.com,布布扣
从输出结果上看实参的值没有受形参的影响!
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace nange_1
{
    class A
    {
        public void listint(params int[] array)
        {
            for (int i = 0; i < array.Length; i++)
            { array[i] = array[i] * 10; 
              Console.WriteLine("{0}",array[i]); 
            }
        }

    }




    class Program
    {
        static void Main(string[] args)
        {
            int []array=new int[]{1,2,3};
            A objA = new A();
            objA.listint(array);
            foreach(int x in array)
            Console.WriteLine("{0}",x);//输出每个元素
            Console.ReadLine();
        }

    }
}
bubuko.com,布布扣
//通过实参的值改变了形参的值

 

 

 

参数数组params

标签:style   blog   http   io   ar   color   sp   for   on   

原文地址:http://www.cnblogs.com/leijiangtao/p/4129226.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!