SoFunction
Updated on 2025-03-06

C# Method of using params modifier to implement variable-length parameter passing


public class Test2
{
    public static void Main()
    {
ShowName("Small A"); // Here you can specify parameters of any length or pass different types of parameters, but the parameter type must be changed to object
ShowName("Small A", "Small B");
    }
    public static void ShowName(params string[] names)
    {
        foreach (string name in names)
        {
        (name);
        }
    }
}