接线员'??' 不能应用于'List <double>类型的操作数

MVK*_*MVK -2 c#

double indexValues = 0;    
var filterValues = Values as List<double> ?? Values as List<string>;
return (from val in filterValues select indexValues++).ToList();
Run Code Online (Sandbox Code Playgroud)

它说,

Operator '??' cannot be applied to operands of type 'List<double>' and 'List<string>'
Run Code Online (Sandbox Code Playgroud)

ValuesIEnumerable,有人可以帮我解决这个错误吗?

Eug*_*tov 8

这是null-coalescing运算符.编译器对此代码的投诉原因是左侧和右侧站点操作数类型应该是相同的类型.在您的代码中List<double>,List<string>是不同的类型.

尝试is检查或转换as并检查它是否为空.