From the course: Advanced C# Programming Concepts

Unlock this course with a free trial

Join today to access over 24,700 courses taught by industry experts.

Solution: Interfaces

Solution: Interfaces

- [Instructor] Okay, let's review the solution to this challenge that I came up with. So here in my code, I created an IRandomizable interface. Inside the interface definition is the GetRandomNum method, which you can see accepts and entered your number and returns and entered your result. And then next, I added the interface declaration to my answer class, which will implement the interface. My implementation of the GetRandomNum function uses the built-in .netclassrandom, which provides a function named Next. And this will generate a random number between zero and the given parameter value, which is the parameter given to my function. And then I just return the value. So we can see that this is the test code down here. All right, so let's go ahead and run it. And sure enough, looks like I'm getting the right result. Let's try it again. Yep, looks great. Let's try it again. All right, it seems like we're returning good random numbers. So that's it. That's my solution. How did you do…

Contents