c# - 返回具有两个数组的元组
问题描述
我正在尝试调用一个函数,该函数返回一个包含两个数组的元组。数组的内容基于checkedListBox 中的选中项。我定义数组并调用函数“storeParametersInArrays”,如下所示。
string[] allowedObjects = new string[checkedListObjects.CheckedItems.Count]; // All allowed objects
string[] notallowedObjects = new string[checkedListObjects.Items.Count - checkedListObjects.CheckedItems.Count]; // All not allowed objects
Tuple<string[], string[]> ObjParameters = storeParametersInArrays(notallowedObjects, allowedObjects, checkedListObjects);
allowedObjects = ObjParameters.Item1;
notallowedObjects = ObjParameters.Item2;
调用的函数定义为:
private Tuple<string[], string[]> storeParametersInArrays(string[] notallowed, string[] allowed, CheckedListBox checkedListBox)
{
int i = 0; // allowed objects
int j = 0; // not allowed objects
int k = 0; // item counter
foreach (object item in checkedListBox.Items)
{
if (!checkedListBox.CheckedItems.Contains(item))
{
notallowed[j++] = checkedListBox.Items[k].ToString();
}
else
{
allowed[i++] = checkedListBox.Items[k].ToString();
}
k++;
}
return Tuple.Create<allowed, notallowed>;
}
我无法返回上述代码示例中的元组。我收到错误“无法将方法组 'Create' 转换为非委托类型 'Tuple'”。
这是我第一次使用元组,我怎样才能返回两个数组而不必调用该函数两次?
我已经看过稍微类似的问题,所以如果问题已经在其他地方得到回答,我会很高兴指出正确的方向。
解决方案
只是改变
return Tuple.Create<allowed, notallowed>;
至
return Tuple.Create(allowed, notallowed);
第一种语法用于泛型:<
第二个用于方法调用:(
推荐阅读
- javascript - SharePoint 的客户端分类选择器
- extentreports - ExtentReports: detachReporter() 方法
- laravel - 迁移时添加多行
- javascript - 对工作日数组进行排序(JavaScript)
- gcov - 将 lcov 与 gcc-8 一起使用
- java - 如何为 Set Map of Sets 的 Java Map 声明 TypeScript 类型?
- nservicebus - AzureStorage 上的 NServiceBus 调度消息花费的时间超过了可见性超时
- sql-server - Serilog.Sinks.MSSqlServer 不填充自定义列
- java - 如何在改造中获得 Array 的响应?
- c - 检查字符串是否包含相同数量的相同字符