Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Question: can I use extension methods? #668

Closed
kasimier-vireq opened this issue Mar 9, 2022 · 3 comments
Closed

Question: can I use extension methods? #668

kasimier-vireq opened this issue Mar 9, 2022 · 3 comments

Comments

@kasimier-vireq
Copy link

I tried to define an extension methods but I'm getting the following error (German; meaning that extension methods need to be defined at top-level, but this is a nested class):

"error CS1109: Die Erweiterungsmethoden müssen in statischen Klassen auf oberster Ebene definiert werden. "Extensions" ist eine geschachtelte Klasse."

@seesharper
Copy link
Collaborator

It means that your extension methods must be top-level methods.

Example.

public static string GetFirstFiveCharacters(this string value)
{
    return value[..5];
}

@kasimier-vireq
Copy link
Author

Yes, but the script thingy wraps all top-level definitions implicitly:
image

@kasimier-vireq
Copy link
Author

Ah, now I get what you meant. The static extension class must be omitted. Great, thanks!
image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants