Click here to Skip to main content
15,885,546 members
Home / Discussions / C#
   

C#

 
AnswerRe: Overloaded Methods with Generics Pin
OriginalGriff30-Mar-20 6:34
mveOriginalGriff30-Mar-20 6:34 
GeneralRe: Overloaded Methods with Generics Pin
#realJSOP30-Mar-20 6:50
mve#realJSOP30-Mar-20 6:50 
GeneralRe: Overloaded Methods with Generics Pin
OriginalGriff30-Mar-20 8:28
mveOriginalGriff30-Mar-20 8:28 
GeneralRe: Overloaded Methods with Generics Pin
#realJSOP31-Mar-20 0:21
mve#realJSOP31-Mar-20 0:21 
AnswerRe: Overloaded Methods with Generics Pin
BillWoodruff30-Mar-20 16:33
professionalBillWoodruff30-Mar-20 16:33 
GeneralRe: Overloaded Methods with Generics Pin
#realJSOP31-Mar-20 0:18
mve#realJSOP31-Mar-20 0:18 
GeneralRe: Overloaded Methods with Generics Pin
BillWoodruff31-Mar-20 5:17
professionalBillWoodruff31-Mar-20 5:17 
AnswerRe: Overloaded Methods with Generics Pin
Richard Deeming31-Mar-20 1:26
mveRichard Deeming31-Mar-20 1:26 
If you call MyMethod with something that has a compile-time type of IEnumerable<T>, you'll call the correct method.

If you call it with something where the compile-time type implements IEnumerable<T>, you'll call the wrong method.
C#
MyMethod(Enumerable.Range(1, 42)); // Calls IEnumerable overload
MyMethod(new[] { 1, 2, 3 }); // Calls T overload
MyMethod(new List<int> { 1, 2, 3 }); // Calls T overload

One workaround might be to add .AsEnumerable() to the method argument.
C#
MyMethod(Enumerable.Range(1, 42)); // Calls IEnumerable overload
MyMethod((new[] { 1, 2, 3 }).AsEnumerable()); // Calls IEnumerable overload
MyMethod((new List<int> { 1, 2, 3 }).AsEnumerable()); // Calls IEnumerable overload




"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer

GeneralRe: Overloaded Methods with Generics Pin
BillWoodruff31-Mar-20 5:32
professionalBillWoodruff31-Mar-20 5:32 
GeneralRe: Overloaded Methods with Generics Pin
Richard Deeming31-Mar-20 8:51
mveRichard Deeming31-Mar-20 8:51 
GeneralRe: Overloaded Methods with Generics Pin
BillWoodruff31-Mar-20 11:49
professionalBillWoodruff31-Mar-20 11:49 
GeneralRe: Overloaded Methods with Generics Pin
Richard Andrew x6431-Mar-20 13:57
professionalRichard Andrew x6431-Mar-20 13:57 
GeneralRe: Overloaded Methods with Generics Pin
Richard Deeming1-Apr-20 0:04
mveRichard Deeming1-Apr-20 0:04 
GeneralRe: Overloaded Methods with Generics Pin
BillWoodruff1-Apr-20 2:07
professionalBillWoodruff1-Apr-20 2:07 
GeneralRe: Overloaded Methods with Generics Pin
Richard Deeming1-Apr-20 2:13
mveRichard Deeming1-Apr-20 2:13 
GeneralRe: Overloaded Methods with Generics Pin
Richard Deeming1-Apr-20 0:15
mveRichard Deeming1-Apr-20 0:15 
GeneralRe: Overloaded Methods with Generics Pin
#realJSOP31-Mar-20 23:26
mve#realJSOP31-Mar-20 23:26 
AnswerRe: Overloaded Methods with Generics Pin
James Curran7-Apr-20 4:48
James Curran7-Apr-20 4:48 
QuestionWpf Excel Pin
RajaMohammed.A26-Mar-20 3:55
RajaMohammed.A26-Mar-20 3:55 
AnswerRe: Wpf Excel Pin
Richard MacCutchan26-Mar-20 4:12
mveRichard MacCutchan26-Mar-20 4:12 
AnswerRe: Wpf Excel Pin
jsc422-Apr-20 2:58
professionaljsc422-Apr-20 2:58 
QuestionC# Oracle SYSDBA connection string not able to working on windows 10? Pin
barathsamkumar25-Mar-20 4:39
barathsamkumar25-Mar-20 4:39 
AnswerRe: C# Oracle SYSDBA connection string not able to working on windows 10? Pin
OriginalGriff25-Mar-20 5:13
mveOriginalGriff25-Mar-20 5:13 
AnswerRe: C# Oracle SYSDBA connection string not able to working on windows 10? Pin
ZurdoDev25-Mar-20 10:07
professionalZurdoDev25-Mar-20 10:07 
QuestionUser List Pin
Richard Andrew x6423-Mar-20 10:40
professionalRichard Andrew x6423-Mar-20 10:40 

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.