Linq中string转int的方法
生活随笔
收集整理的這篇文章主要介紹了
Linq中string转int的方法
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
Linq中string轉int的方法
在做批量刪除時,需把一串id值所對應的數據刪除,調試出現問題:
?
Linq語句中如果使用ToString()進行類型轉換,編譯時不會報錯,但執行時會出現如下錯誤:
“LINQ to Entities 不識別方法"System.String ToString()",因此該方法無法轉換為存儲表達式。”
原因是Linq不支持ToString()函數。
?
可用下述方法進行轉換解決:
string source = "1,2,3,4,5";
List<int> result = new List<string>(source.Split(',')).ConvertAll(i => int.Parse(i));
?
注:
需引用下列命名空間
using System.Collections.Generic;
using System.Linq;
轉載于:https://www.cnblogs.com/xdot/p/6841340.html
總結
以上是生活随笔為你收集整理的Linq中string转int的方法的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: SQL Server 统计信息更新时采样
- 下一篇: 可视化爬虫资料