C# 无法隐式转换类型';系统元组<;字符串,字符串,双精度>';至';System.Collections.Generic.List<;系统元组<;字符串,字符串,双精度>&燃气轮机';
我有两个元组C# 无法隐式转换类型';系统元组<;字符串,字符串,双精度>';至';System.Collections.Generic.List<;系统元组<;字符串,字符串,双精度>&燃气轮机';,c#,tuples,C#,Tuples,我有两个元组 List<Tuple<string, string, double>> _AllBatchList = new List<Tuple<string, string, double>>(); List<Tuple<string, string, double>> _tmpBatchList = null; 并遍历元组 foreach (var item in _tmpBatchList) {
List<Tuple<string, string, double>> _AllBatchList = new List<Tuple<string, string, double>>();
List<Tuple<string, string, double>> _tmpBatchList = null;
并遍历元组
foreach (var item in _tmpBatchList)
{
doc.Lines.BatchNumbers.BatchNumber = item.Item1;
doc.Lines.BatchNumbers.Quantity = double.Parse(_WtmpTotalQty);
doc.Lines.BatchNumbers.Add();
}
但这条线会产生上述误差
_tmpBatchList = _AllBatchList.Find(t => t.Item2 == _WtmpItemNo)
需要建议来解决此问题在这种情况下,Find()
方法将返回类型为Tuple
的对象
您试图将其分配给List
类型的变量,因此出现错误
请尝试将找到的对象指定给变量:
var obj = _AllBatchList.Find(t => t.Item2 == _WtmpItemNo);
如果您试图查找满足此条件的所有项目,请改用Where
方法:
_tmpBatchList = _AllBatchList.Where(t => t.Item2 == _WtmpItemNo);
什么是
AllBatchList
?或者,您的意思是\u AllBatchList
?您发布了所有代码吗?@Xiaoy312请参考您更改的修改代码,哪一行抛出了错误。。。您确定是新行引起了异常吗?返回列表中的单个元素。我想你是想要的。到目前为止,我的问题的正确答案是什么
var obj = _AllBatchList.Find(t => t.Item2 == _WtmpItemNo);
_tmpBatchList = _AllBatchList.Where(t => t.Item2 == _WtmpItemNo);