Created
November 13, 2016 11:20
-
-
Save ichengzi/7cfc4b28399b4c0a9920d281b59de2fb to your computer and use it in GitHub Desktop.
LINQ - via cz
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var input = "PQR"; | |
DataTable dt = new DataTable(); | |
dt.Columns.Add("PId", typeof(Int32)); | |
dt.Columns.Add("PName", typeof(string)); | |
dt.Columns.Add("Qty", typeof(Int32)); | |
dt.Rows.Add(123, "XYZ", 2); | |
dt.Rows.Add(223, "ABC", 4); | |
dt.Rows.Add(434, "PQR", 33); | |
var stkLists = dt.AsEnumerable().ToList(); | |
var matchList = stkLists.Where(m => m["PName"].ToString().StartsWith(input)).ToList(); | |
var FinalList = matchList.Concat(stkLists.Except(matchList).ToList()); | |
// 输入值匹配的项放最前边,剩余的按原来的顺序 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment