我有这行代码:
IEnumerable<double> katlar = ilanlarQuery.ToList()
.Select(r => r.BulunduguKat.Value)
.OrderBy(f => f);
我收到错误,因为BulunduguKat.Value
是int,但katlar
是double。如何在此声明中将BulunduguKat.Value
转换为double?感谢。
答案 0 :(得分:9)
最直接的方式:只需转换为double
即可。通过这样做,您告诉TResult
此Select
操作的double
类型是IEnumerable<double>
- 使其成为IEnumerable<double> katlar = ilanlarQuery.Select(r => (double)r.BulunduguKat.Value)
.OrderBy(f => f);
IEnumerable<double> katlar = ilanlarQuery.Select<YourType,double>(i => i.BulunduguKat.Value)
.OrderBy(f => f)();
由于int可以隐式转换为double,因此也可以使用:
.ToList()
此外,如您所见,您可以在之前删除BulunduguKat
如果Tim建议确实Nullable<int>
是//If you don't want them in the result collection:
var katlar = ilanlarQuery.Where(r => r.BulunduguKat.HasValue)
.Select(r => (double)r.BulunduguKat.Value)
.OrderBy(f => f)
//If you want them with some default value:
var katlar = ilanlarQuery.Select(r => (double)(r.BulunduguKat.HasValue ? r.BulunduguKat.Value : 0))
.OrderBy(f => f);
,那么您应该决定:
Sub LöscheDatensatz()
Application.ScreenUpdating = False
With ActiveSheet
.unprotect Password:="test"
If Cells(Selection.Row, 1).Locked = False Then
Selection.EntireRow.Delete
End If
.Protect Password:="test", AllowFiltering:=True
End With
Application.ScreenUpdating = True
End Sub
答案 1 :(得分:0)
ds.Tables["#KAMPANYA"].AsEnumerable().Select(s => Convert.ToInt32(s["KAMNO"])).ToList()