For example, I Have such code:
IEnumerable<RSuspectOperationCode> distinctCodes = this.Distinct(); // "this" is some collection
this.Clear()
distinctCodes.Count();
As LINQ is deferred execution query - Count gives us 0. I'm interesting - is there a approach to get a distinct collection with in-place result calculation and breaking link between source and result collection, that clearing source collection won't affect result collection?
My workaround:
List<RSuspectOperationCode> distinctCodes = new List<RSuspectOperationCode>();
distinctCodes.AddRange(this.Distinct(comparer));
this.Clear();
distinctCodes.Count();
But, I wonder, is there more elegant/shorter way?