Coding Exercise: Extension Methods
Test yourself on the extension method.
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 string,Lucky
orNot Lucky
(in the example below, the lucky numbers are 7 and 13). - Display whether or not the number is lucky.
Sample input and output
The finished output of the program should look like the examples below:
Example 1:
Enter a number to find out if it is lucky: 7
The number 7 is lucky!
Example 2:
Enter a number to find out if it is lucky: 12
The number 12 is NOT lucky!
Get hands-on with 1200+ tech skills courses.