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.
- Display the prompt:
Enter a number to find out if it is lucky:
- Create an extension method for an
int
that returns a stringLucky
orNot Lucky
(in the example below, the lucky numbers are 7 and 13). - Display whether or not the number is lucky.
Get hands-on with 1400+ tech skills courses.