Methods (Exercise) – Learn C#

0  comments

This is an exercise for this YouTube video.

Happy learning and good luck!

 

[qsm quiz=7]

 

Assignment: Write a method which will add two integers together.

 

 

Click to see the answer
static int Add(int a, int b)
{
    return a + b;
}

 

 

 

Assignment: Create a method which will be able to either add or subtract two numbers.

 

 

Click to see the answer
static int AddOrSubtract(int a, int b, bool isAddition)
{
    if (isAddition)
        return a + b;

    return a - b;
}

 

 

 

 

About the author 

Matt Rešetár

Matt is an app developer with a knack for teaching others. Working as a freelancer and most importantly developer educator, he is set on helping other people succeed in their Flutter app development career.

You may also like

{"email":"Email address invalid","url":"Website address invalid","required":"Required field missing"}
>