Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Consider following class which stores the information about external urls.
- 1: class LinkInfo
- 2: {
- 3: public int Ord { get; set; }
- 4: public string Url { get; set; }
- 5: }
- In your application you somehow retrieve the list of such items:
- 1: List<LinkInfo> l = new List<LinkInfo>()
- 2: {
- 3: new LinkInfo() { Ord = 1, Url = "" },
- 4: new LinkInfo() { Ord = 2, Url = "test1" },
- 5: new LinkInfo() { Ord = 3, Url = "test1" },
- 6: new LinkInfo() { Ord = 4, Url = "test2" },
- 7: new LinkInfo() { Ord = 5, Url = "" }
- 8: };
- Your goal is to use Linq to filter this list in a special way:
- if the Url is empty - the item is always returned,
- if the Url is nonempty - only one item with such Url is returned.
- In the above case the Linq expression should return:
- 1: {
- 2: new LinkInfo() { Ord = 1, Url = "" },
- 3: new LinkInfo() { Ord = 2, Url = "test1" },
- 4: new LinkInfo() { Ord = 4, Url = "test2" },
- 5: new LinkInfo() { Ord = 5, Url = "" }
- 6: };
- or
- 1: {
- 2: new LinkInfo() { Ord = 1, Url = "" },
- 3: new LinkInfo() { Ord = 3, Url = "test1" },
- 4: new LinkInfo() { Ord = 4, Url = "test2" },
- 5: new LinkInfo() { Ord = 5, Url = "" }
- 6: }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement