Level 4 — Classes
Methods
Original notes by SunDiaL · View English source
A method is just a class function.
No idea why a new term was needed... nobody really cares if you say function or method really... Technically, since C# is a fully object oriented language, that means everything lives inside a class -> every function is a method.
Defining a method
You do it just as you would do a function, except it within the scope of the class.
class ExampleClass
{
//empty constructor
public ExampleClass() { }
public ExampleMethod()
{
//do something
}
}
Invoking a method
You do is just as you would do a function, except you have to go through an instance of your class to reach it
class Program
{
public void main()
{
ExampleClass ex = new ExampleClass();
ex.ExampleMethod();
}
}