Let’s say I have a simple function like this:
public static string randomthing(string var1)
{
string var2 = "hello world";
return var2;
}
I would like to be able to call it from different classes. How can I do it?
I tried to create a blank file and just paste the function there but of course it doesn’t work that way.
If you want to share code, you need to create a third class that can be used by the other classes.
This can be done as an extension method, a static class or regular class (meaning you need an instance of the class).
Static class:
Extension method:
Regular class: