将列表转换为参数C# [英] Convert list to params C#
本文介绍了将列表转换为参数C#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有以下列表:
var myList = new List<KeyValuePair<string, object>>();
此功能:
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);
推荐答案
您的方法声明KeyValuePair<string, object>[] list
指出它将接受一个数组,因此您需要像这样将列表转换为数组
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());
这篇关于将列表转换为参数C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文