Click here to Skip to main content
15,892,059 members
Home / Discussions / .NET (Core and Framework)
   

.NET (Core and Framework)

 
GeneralRe: Mixed mode assembley Pin
Richard MacCutchan22-Nov-11 1:09
mveRichard MacCutchan22-Nov-11 1:09 
AnswerRe: Mixed mode assembley Pin
NikulDarji23-Nov-11 3:08
NikulDarji23-Nov-11 3:08 
QuestionMessage Removed Pin
17-Nov-11 9:36
professionalN_tro_P17-Nov-11 9:36 
AnswerRe: IEnumerable Unboxing and ToMethods Pin
Luc Pattyn17-Nov-11 10:40
sitebuilderLuc Pattyn17-Nov-11 10:40 
GeneralRe: IEnumerable Unboxing and ToMethods Pin
Not Active17-Nov-11 12:10
mentorNot Active17-Nov-11 12:10 
GeneralRe: IEnumerable Unboxing and ToMethods Pin
Luc Pattyn17-Nov-11 12:25
sitebuilderLuc Pattyn17-Nov-11 12:25 
GeneralMessage Removed Pin
18-Nov-11 3:46
professionalN_tro_P18-Nov-11 3:46 
AnswerRe: IEnumerable Unboxing and ToMethods Pin
Luc Pattyn18-Nov-11 4:08
sitebuilderLuc Pattyn18-Nov-11 4:08 
when a method promises to return an IEnumerable, then it can actually return a List, an Array, a StringCollection, ..., as they each implement (hence ARE) IEnumerables. IEnumerables is just a more vague description of a pretty specific object which could be a List, an Array, etc. There is no conversion, no "new object" at all.

Collin Jasnoch wrote:
why not just use List<T> or arrays for your return type?


I see at least two reasons why it could make sense:

1. you want to return something that the caller can perform only some operations on; when you return a List as an IEnumerable, the caller can enumerate the items in the list, and change those items, however he can't change the list itself. That is encapsulation.
2. assuming all that is required by the caller is IEnumerable, why offer him more? As a provider of the callee, you could change your implementation (say from arrays to lists), and still return the object as an IEnumerable, the caller wouldn't notice. And sometimes, you might return either an array or a List, using different return statements in your one implementation.

Example:
Since .NET 1.0 (when no generics existed) Directory.GetFiles has been defined as returning an array, which is expensive promise: while collecting the data, they don't know yet how many items will be present, so they must count first, allocate an array, stuff it, and then return it. Had it been declared returning an IEnumerable from day one, the current implementation could have taken full advantage of a generic list.

Smile | :)
Luc Pattyn [My Articles] Nil Volentibus Arduum

GeneralMessage Removed Pin
18-Nov-11 4:37
professionalN_tro_P18-Nov-11 4:37 
AnswerRe: IEnumerable Unboxing and ToMethods Pin
Luc Pattyn18-Nov-11 4:45
sitebuilderLuc Pattyn18-Nov-11 4:45 
GeneralMessage Removed Pin
18-Nov-11 5:21
professionalN_tro_P18-Nov-11 5:21 
GeneralRe: IEnumerable Unboxing and ToMethods Pin
Luc Pattyn18-Nov-11 5:24
sitebuilderLuc Pattyn18-Nov-11 5:24 
GeneralRe: IEnumerable Unboxing and ToMethods Pin
Addy Tas7-Dec-11 11:02
Addy Tas7-Dec-11 11:02 
GeneralMessage Removed Pin
12-Dec-11 4:10
professionalN_tro_P12-Dec-11 4:10 
GeneralRe: IEnumerable Unboxing and ToMethods Pin
Addy Tas12-Dec-11 9:45
Addy Tas12-Dec-11 9:45 
QuestionPrinting: HasMorePages ignored Pin
W Balboos, GHB17-Nov-11 6:48
W Balboos, GHB17-Nov-11 6:48 
AnswerRe: Printing: HasMorePages ignored Pin
Richard MacCutchan17-Nov-11 8:38
mveRichard MacCutchan17-Nov-11 8:38 
GeneralRe: Printing: HasMorePages ignored Pin
W Balboos, GHB17-Nov-11 8:48
W Balboos, GHB17-Nov-11 8:48 
AnswerRe: Printing: HasMorePages ignored Pin
Luc Pattyn17-Nov-11 9:21
sitebuilderLuc Pattyn17-Nov-11 9:21 
GeneralRe: Printing: HasMorePages ignored Pin
W Balboos, GHB17-Nov-11 9:48
W Balboos, GHB17-Nov-11 9:48 
AnswerRe: Printing: HasMorePages ignored Pin
Luc Pattyn17-Nov-11 9:59
sitebuilderLuc Pattyn17-Nov-11 9:59 
Question64 bit vs. 32 bit for developers... Pin
Jun Du17-Nov-11 3:44
Jun Du17-Nov-11 3:44 
AnswerRe: 64 bit vs. 32 bit for developers... Pin
Richard MacCutchan17-Nov-11 6:58
mveRichard MacCutchan17-Nov-11 6:58 
AnswerRe: 64 bit vs. 32 bit for developers... Pin
Luc Pattyn17-Nov-11 9:27
sitebuilderLuc Pattyn17-Nov-11 9:27 
AnswerRe: 64 bit vs. 32 bit for developers... Pin
David Skelly17-Nov-11 22:33
David Skelly17-Nov-11 22:33 

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.