Click here to Skip to main content
15,888,610 members
Home / Discussions / C#
   

C#

 
AnswerRe: GZipStream appears to malfunction (24K maximum) Pin
Luc Pattyn6-Jan-12 7:00
sitebuilderLuc Pattyn6-Jan-12 7:00 
GeneralRe: GZipStream appears to malfunction (24K maximum) Pin
Paladin20006-Jan-12 7:51
Paladin20006-Jan-12 7:51 
GeneralRe: GZipStream appears to malfunction (24K maximum) Pin
Paladin20006-Jan-12 9:02
Paladin20006-Jan-12 9:02 
GeneralRe: GZipStream appears to malfunction (24K maximum) Pin
jschell6-Jan-12 9:11
jschell6-Jan-12 9:11 
GeneralRe: GZipStream appears to malfunction (24K maximum) Pin
harold aptroot6-Jan-12 23:34
harold aptroot6-Jan-12 23:34 
AnswerRe: GZipStream appears to malfunction (24K maximum) Pin
Luc Pattyn8-Jan-12 18:46
sitebuilderLuc Pattyn8-Jan-12 18:46 
QuestionCompression/Decompression using C#(Only using C# APIs. no third party) Pin
KASR16-Jan-12 3:08
KASR16-Jan-12 3:08 
AnswerRe: Compression/Decompression using C#(Only using C# APIs. no third party) Pin
OriginalGriff6-Jan-12 3:48
mveOriginalGriff6-Jan-12 3:48 
GeneralRe: Compression/Decompression using C#(Only using C# APIs. no third party) Pin
KASR18-Jan-12 20:29
KASR18-Jan-12 20:29 
QuestionTest Tools Pin
Pierre besquent5-Jan-12 23:52
Pierre besquent5-Jan-12 23:52 
QuestionIEnumerable OrderBy on a text field Pin
__John_5-Jan-12 22:48
__John_5-Jan-12 22:48 
AnswerRe: IEnumerable OrderBy on a text field Pin
Wayne Gaylard5-Jan-12 23:18
professionalWayne Gaylard5-Jan-12 23:18 
AnswerRe: IEnumerable OrderBy on a text field Pin
manognya kota5-Jan-12 23:22
manognya kota5-Jan-12 23:22 
GeneralRe: IEnumerable OrderBy on a text field Pin
__John_5-Jan-12 23:46
__John_5-Jan-12 23:46 
GeneralRe: IEnumerable OrderBy on a text field Pin
__John_5-Jan-12 23:55
__John_5-Jan-12 23:55 
GeneralRe: IEnumerable OrderBy on a text field Pin
manognya kota6-Jan-12 0:36
manognya kota6-Jan-12 0:36 
GeneralRe: IEnumerable OrderBy on a text field Pin
__John_6-Jan-12 0:44
__John_6-Jan-12 0:44 
GeneralRe: IEnumerable OrderBy on a text field Pin
manognya kota6-Jan-12 0:58
manognya kota6-Jan-12 0:58 
GeneralRe: IEnumerable OrderBy on a text field Pin
manognya kota6-Jan-12 1:23
manognya kota6-Jan-12 1:23 
GeneralRe: IEnumerable OrderBy on a text field Pin
__John_6-Jan-12 1:59
__John_6-Jan-12 1:59 
GeneralRe: IEnumerable OrderBy on a text field Pin
manognya kota6-Jan-12 2:12
manognya kota6-Jan-12 2:12 
GeneralRe: IEnumerable OrderBy on a text field Pin
Vincent Blais6-Jan-12 2:35
professionalVincent Blais6-Jan-12 2:35 
GeneralRe: IEnumerable OrderBy on a text field Pin
__John_6-Jan-12 2:47
__John_6-Jan-12 2:47 
GeneralRe: IEnumerable OrderBy on a text field Pin
__John_6-Jan-12 3:12
__John_6-Jan-12 3:12 
GeneralRe: IEnumerable OrderBy on a text field Pin
Vincent Blais6-Jan-12 4:00
professionalVincent Blais6-Jan-12 4:00 
__John_ wrote:


It uses a 'lazy' strategy, ie. only evaluating an expression or executing a function when the result is actually needed, am I right?


Yes you are right. It's a principle of Linq to defer execution until is needed. And Linq also evaluate only the elements needed to return the result
Let's take Wayne List and do some examples

List<Person> peoples = new List<Person> {new Person("wayne"), new Person("sarah"), new Person("mark"), new Person("simon"), new Person("ashleigh"), new Person("dave"), new Person("connor"), new Person("bronwyn"), new Person("chantelle"), new Person("will"), new Person("chris")};

int Count = people.Count(p => p.Name.StartsWith("w")); //<-- Count is a greedy operator and all persons are evaluated for a result of 2.

var firstperson = people.Where(p => p.Name.Length == 5).Take(3);
foreach (var p in firstperson) // <-- evaluation start where and only Wayne, Sarah, Mark and Simon will be evaluated. The rest of the list is left alone
{
   Console.WriteLine(p.Name);
}

// And to show you when Linq expression are evaluated, try 
var firstperson2 = people.Where(p => p.Name.Length == 5).Take(3);
people.Insert(1, new Person("Vince"));

foreach (var p in firstperson) // <-- evaluation start where and only Wayne, Vince ans Sarah, will be evaluated. The rest of the list is left alone
{
    Console.WriteLine(p.Name);
}


http://blogs.msdn.com/b/charlie/archive/2007/12/09/deferred-execution.aspx[^]


__John_ wrote:
BTW: How can I enumerate the results more that once?

If you use a Enumerator<t>, you can use Reset to set the enumerator to its initial position, which is before the first element in the collection.
But if you use a foreach loop, you can reuse an Enumerable<t> many times. The foreach loop will start at the beginning every time.
Vince

Remember the dead, fight for the living

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.