program.cs

来自「这是.net2005学习不可缺少的教程」· CS 代码 · 共 36 行

CS
36
字号
// cs_params.cs
using System;
public class MyClass
{

    public static void UseParams(params int[] list)
    {
        for (int i = 0; i < list.Length; i++)
        {
            Console.WriteLine(list[i]);
        }
        Console.WriteLine();
    }

    public static void UseParams2(params object[] list)
    {
        for (int i = 0; i < list.Length; i++)
        {
            Console.WriteLine(list[i]);
        }
        Console.WriteLine();
    }

    static void Main()
    {
        UseParams(1, 2, 3);
        UseParams(1, 2, 3,4,5,6,7,8);
        UseParams2(1, 'a', "test",true);

        // An array of objects can also be passed, as long as
        // the array type matches the method being called.
        //int[] myarray = new int[3] { 10, 11, 12 };
        //UseParams(myarray);
    }
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?