Can a params[] variable hold a list, that has been passed as a parameter through a method in C#?
Wrote a method(AddIntegers) which requires multiple values to be taken as parameters. On the parameter list of a method, there is a params[] variable that is receiving the values thrown, when the method call is made in the Main method. But there is an exception that says "Cannot convert from system.collections.generic.List<> to an integer. Anyone knows why does that happen?
**** this is within the Main Method****
string Demostring = Console.ReadLine();
string[] tokens = Demostring.Split(',');
List<int> nums = new List<int>();
int oneNum;
foreach(string s in tokens)
{
if (Int32.TryParse(s, out oneNum))
nums.Add(oneNum);
}
int result1 = AddIntegers(nums);
**** this is the method to be called****
public static int AddIntegers(params int[] Restnum)
{
int result = 0;
foreach(int temp in Restnum)
{
result += temp;
}
return result;
}