尝试从单个函数返回 2 个列表值
我正在使用这段代码:-
public KeyValuePair<int, int> encrypt(string password)
{
List<int> key = new List<int>();
List<int> code = new List<int>();
/*
do stuff, do some more stuff and go!
*/
return new KeyValuePair<List<int>,List<int>>(key,code);
}
这里我试图返回 2 List<int>
值但发生错误。如何从单个函数返回 2 个列表值
更新
找到答案了,我们得到了 2 个正确答案,这就是为什么我不只选择一个,因为两个都很好
HadiRj 的回答
通过Enigmativity回答
如果你想使用我的代码,那么这是它的正确版本:-
public KeyValuePair<List<int>, List<int>> encrypt(string password)
{
List<int> key = new List<int>();
List<int> code = new List<int>();
/*
do stuff, do some more stuff and go!
*/
return new KeyValuePair<List<int>,List<int>>(key,code);
}
最佳答案
在这种情况下,一个相当简洁的方法是使用 out
参数。
public void encrypt(string password, out List<int> key, out List<int> code)
{
key = new List<int>();
code = new List<int>();
/*
do stuff, do some more stuff and go!
*/
}
关于c# - 如何从单个函数返回多个 List<> 值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34468691/