Solution: Extension Methods

Let’s look at the solution to the extension method exercise.

We'll cover the following

Problem

This activity uses an extension method to determine if a number is lucky. Create a console application called Lucky Number that meets the requirements below.

  1. Display the prompt: Enter a number to find out if it is lucky:
  2. Create an extension method for an int that returns a string Lucky or Not Lucky (in the example below, the lucky numbers are 7 and 13).
  3. Display whether or not the number is lucky.

Get hands-on with 1400+ tech skills courses.