Last active
December 15, 2015 16:29
-
-
Save anakahala/5289173 to your computer and use it in GitHub Desktop.
LINQで動的検索(拡張メソッド使用)
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
| /// <summary> | |
| /// Person | |
| /// </summary> | |
| private class Person | |
| { | |
| public int Id { get; set; } | |
| public string Name { get; set; } | |
| } | |
| /// <summary> | |
| /// PersonList | |
| /// </summary> | |
| private List<Person> personList = null; | |
| /// <summary> | |
| /// NameのList取得 | |
| /// </summary> | |
| /// <param name="name"></param> | |
| /// <returns></returns> | |
| private List<string> GetNameList(string name) | |
| { | |
| var q = from d in this.personList select d; | |
| if (!String.IsNullOrEmpty(name)) | |
| { | |
| // パラメータのnameが指定されている場合、含まれているものを取得 | |
| q = q.Where(v => v.Name.Contains(name)); | |
| } | |
| return q.OrderBy(v => v.Id).Select(v => v.Name).ToList(); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment