Menu
Coddy logo textTech

Methods

Lesson 4 of 12 in Coddy's Basics of Classes and Objects in C# course.

You might already be familiar with methods from Methods in C# course (If not, you should do it!)

To create a method in class, use:

class MyClass {
	public void myMethod() {
	
	}
}

In the above example, we create a class named MyClass with a method called myMethod that returns nothing (void).

Note the public keyword, it indicates the method can be accessed by objects, we won't access this topic in this course - but add it to all your methods.

quiz iconTest yourself

This lesson includes a short quiz. Start the lesson to answer it and track your progress.

challenge icon

Challenge

Easy

Create a class named Sum with a method named calc that takes two arguments (integers) and returns the sum of the two numbers.

Try it yourself

// Write code here

All lessons in Basics of Classes and Objects in C#