Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- static void Main(string[] args)
- {
- // create a list with 2 elements
- var q1Items = new List<string>()
- {
- "Foo", "Bar"
- };
- // aaahhh LINQ will deffer the execution of this query until it's value is actually used (i.e. .ToList())
- var which = q1Items.Where(x => x != "Bar");
- // which didn't run yet
- q1Items.Add("Baz");
- // q1Items has 3 elements now. the actual where query will happen on the next line
- var nonBar = which.ToList();
- // nonBar has 2 items now ("Foo" and "Baz")
- Console.WriteLine(nonBar.Count); // print 2
- Console.ReadKey();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement