Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert list to params C#

I have this following list:

var myList = new List<KeyValuePair<string, object>>();

And this function:

public void Test(params KeyValuePair<string, object>[] list)

How can I do a conversion of the list to params when using the function? Like that:

Test(myList);
like image 502
AgresivD Avatar asked Mar 21 '17 09:03

AgresivD


1 Answers

You method declaration KeyValuePair<string, object>[] list states that it will accept an array so you need to convert your list to array like this

Test(myList.ToArray());
like image 81
Nikhil Agrawal Avatar answered Oct 05 '22 00:10

Nikhil Agrawal