Joel Joel - 4 years ago 75
C# Question

How to call function with List in head

I want to send along several integers with my function through a list like this:

public string createCompleteJump(List<int>kID)


kID is they key ID which is connected to several dictionaries hence why it is important to select different integers.

function:

public string createCompleteJump(List<int>kID)
{
// List<int> kID = new List<int>(); // Key ID
double vID = 3; // Value ID
string v2ID = "Fram├ąt";
var myKey = qtyScrews[kID[0]].FirstOrDefault(y => y == vID);
var myKey2 = qtyFlips[kID[1]];
var myKey3 = jumpCombination[kID[2]].FirstOrDefault(y => y == v2ID);
var myKey4 = jumpHeight[kID[3]];
var myKey5 = startPos[kID[4]];

var str = $"{myKey}{myKey2}{myKey3}{myKey4}{myKey5}";
Console.Write("\nCompleteJump:" + str);
return str;
}


How would I send along 5 arguments when calling the function through a list?
Eg:

public string createCompleteJump(3,4,2,3,4)

Answer Source

use params keyword:

public string createCompleteJump(params int[] kID)

https://msdn.microsoft.com/library/w5zay9db.aspx

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download