How to reference proper non-generic overload in c#? -


I instead To select the appropriate surcharge?

  using the system; Using System.Collections.Generic; Namespace Console Application 2 {Class A {} class B: A {} class C: A {} class program {static zero main (string [] arg) {var l1 = new list & lt; C & gt; (); Var l2 = new list & lt; C & gt; (); Comparator & lt; C & gt; (L1, L2, ???????); } Compare to zero (ca, cb) {} compare zero (ba, bb) {} compare zero & gt; T & gt; (IiLIT & lt; T & gt; A, ILIST & lt; T & gt; B, Action & lt; T, T & gt; comparator) for (int i = 0; i & lt; a.Count; i ++) comparator (A [i], b [ii]); }}}}  

You need to make the statics static and correct the name of the method is. You can use the type concept on the initial call compare :

  Fixed wide men (string [] AGR) {var l1 = new list & lt; C & gt; (); Var l2 = new list & lt; C & gt; (); Compare (L1, L2, compare); } Constant zero comparison (Si, cb) {} Constant zero comparison (BA, Bb) {} Constant zero comparison & lt; T & gt; (IiLIT & lt; T & gt; A, iiLIT & lt; T & gt; B, Action & lt; T; T & gt; comparator) {for (int i = 0; i & lt; a.Qount; i ++) comparator (a [i], b [i]); }  

There is no ambiguity in this case - compare (C, C) is the only way in the group that is action < C, C & gt; If you have the compare (A, A) method, the more specific method will still be chosen. If you get ambiguity instead:

  Compare static zero (A, cb) {} Compare static zero (C A, A B) {}  

However, I strongly recommend that in such cases, try to avoid overloading wherever possible. Give methods different names - it will be very easy to read, and avoid any ambiguity.


Comments

Popular posts from this blog

c# - ListView onScroll event -

PHP - get image from byte array -

Linux Terminal Problem with Non-Canonical Terminal I/O app -