C
C#5w ago
Cykotech

Extension Methods

I need help understanding extension methods
5 Replies
reflectronic
reflectronic5w 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
ACiDCA75w ago
meeh reflctronic was faster -.-
Cykotech
Cykotech5w 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
KidKai255w ago
"So if I need to supply an additional parameter, do I just add it like I would a normal method?" Yes
Cykotech
Cykotech5w 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
More Posts
I'm having problem making a post in swagger. Its a one to many relationship where "Produto" is one.I have the "Produto", and i shouldn't need any "Material" or "MovimentacaoMaterial", but in swagger MAUI for Android requires wasi-experimental to be installed but it is already installedHi! So I am trying to MAUI application on an android emulator but when building for android it failC# Yaml error```cs using System.Windows.Forms; using YamlDotNet.Serialization; using YamlDotNet.Serialization.NamUnable to determine reason for publish errorI get the following result when publishing my application (exe file to folder) From looking at the c✅ Why I'm getting ArgumentException/System.Windows.Markup.XamlParseException exception?Hey! I was refactoring another part of this project and some how this part of the application broke recommendation for coursei need a good course that contains the updates in .net 8Getting checked for username instead of email attribute in Identity framework in ASP.NET Core MVCI wanted to ask the question here but the character limit won't let me. I have posted it on Stack OWhere do I code?!Hello a little query! I just started learning C#, it's my second language let's say. Other than thaData Grid View is not showing data.Hi, I am writing a library project with N Layered Architecture, like I mentioned in the thread, DGV when to use switches and when to use if statements?do i just use switches if i need more than one if statement? and what is using switches instead of i