C
C#15mo ago
eid

interface vs extension method vs method in class

what is better? to have a method directly in type or make the type implement it from interface or make the type have it by extension method?
6 Replies
this_is_pain
this_is_pain15mo ago
$itdepends
this_is_pain
this_is_pain15mo ago
it's not a priori choice
eid
eidOP15mo ago
i know when to use interface, extension method,and the member method. i mean if i have method it's name is map like select, i want type to have it(i can edit type),(i don't need to make the type interchangeably or use it in polymorphism) i make map as a member method in it, or as extenion method, or interface only i need any type that has map to be mapable, mean(has method map)
this_is_pain
this_is_pain15mo ago
it's kinda difficult to understand you, can you make an example with code?
lycian
lycian15mo ago
only i need any type that has map to be mapable, mean(has method map)
So you're saying you don't know if the type has Map or not at compile time?

Did you find this page helpful?