C
C#7mo ago
Cykotech

Extension Methods

I need help understanding extension methods
5 Replies
reflectronic
reflectronic7mo ago
static class Class
{
public static void NotExtension(string s, int y) { ... }
}

// ok
Class.NotExtension("A", 100);

static class Class2
{
public static void Extension(this string s, int y) { ... }
}

// ok
Class2.Extension("A", 100);
// also ok
"A".Extension(100); // <- this is the only difference between a regular static method and an extension method
static class Class
{
public static void NotExtension(string s, int y) { ... }
}

// ok
Class.NotExtension("A", 100);

static class Class2
{
public static void Extension(this string s, int y) { ... }
}

// ok
Class2.Extension("A", 100);
// also ok
"A".Extension(100); // <- this is the only difference between a regular static method and an extension method
ACiDCA7
ACiDCA77mo ago
meeh reflctronic was faster -.-
Cykotech
CykotechOP7mo ago
So then it seems like I understand it better than I realize Exercism is just weird with how they want me to implement it.
KidKai25
KidKai257mo ago
"So if I need to supply an additional parameter, do I just add it like I would a normal method?" Yes
Cykotech
CykotechOP7mo ago
Yeah nevermind they just named all the methods in the exercise similar things and I was reading the overload error wrong. I appreciate the help though. That's typically my problem though is that I don't read errors correctly :JoyGonnaAscend:
Want results from more Discord servers?
Add your server