【发布时间】:2020-11-01 16:52:00
【问题描述】:
将params 数组传递给另一个函数时如何扩展它。
考虑以下示例:
public class TestClass
{
public static void Main()
{
TestParamFunc(1, "1", 1.0f, 1.0);
Console.ReadKey();
}
private static void TestParamFunc(params object[] parameters)
{
//At the moment the DeeperTestParamFunc receives the following parameters: { int, object[] }
//How to expand this to { int, int, string, float, double } ?
//So that { 1, 1, "1", 1.0f, 1.0 } is received.
DeeperTestParamFunc(1, parameters);
}
public static void DeeperTestParamFunc(params object[] parameters)
{
foreach(object obj in parameters)
{
Console.WriteLine(obj.GetType().ToString());
}
}
}
输出:
System.Int32
System.Object[]
我想要的输出:
System.Int32
System.Int32
System.String
System.Single
System.Double
【问题讨论】:
标签: c# arrays parameters expand