Log in from a computer to take this course

You'll need to log in from a computer to start Learn C#. But you can practice or keep up your coding streak with the Codecademy Go app. Download the app to get started.

apple storegoogle store
Learn

Well done! We learned two shortcuts for defining methods:

Expression-bodied definitions can be used for one-line method bodies.

bool isEven(int num) => num % 2 == 0;

Lambda expressions can be used to create an anonymous method:

bool hasEvenNumbers = Array.Exists(numbers, (int num) => num % 2 == 0 );

You learned two “sub-shortcuts” within lambda expressions:

  • You can remove the parameter type if it can be inferred:

    bool hasEvenNumbers = Array.Exists(numbers, (num) => num % 2 == 0 );
  • You can remove the parentheses if there is one parameter:

    bool hasEvenNumbers = Array.Exists(numbers, num => num % 2 == 0 );

Instructions

Check out the alternate expressions in the text editor! Make sure you understand this code before moving on.

Take this course for free

Mini Info Outline Icon
By signing up for Codecademy, you agree to Codecademy's Terms of Service & Privacy Policy.

Or sign up using:

Already have an account?