课程: C# Practice: Attributes

Explore the CoderPad UI - C#教程

课程: C# Practice: Attributes

Explore the CoderPad UI

- [Presenter] This course consists of automated code challenges that appear when you click on the challenge links in the course table of contents. Each challenge includes instructions that describe your task. There is a pair of code editors where you create and test your own solution to the challenge. These challenges are hosted by CoderPad and they appear in the same area of the course page where you watch the course videos. We recommend using a desktop browser for the best experience with code challenges but you can use the LinkedIn Learning mobile app if you prefer. Let's start with a guided tour of the CoderPad UI. It's divided into four areas. On the left-side, we have the instructions on the top and on the bottom-left is the console output. On the right side of the screen are two code editors. On the top is the editor where you write your solution and on the bottom is the test code. This tells you how your code is going to be called. Give you some clues. You can resize the UI if you desire by dragging these handles either up and down or left and right. We'll start by looking at the instructions on the left. Each challenge has instructions that include the description of the challenge and other information that helps you solve the challenge. In this course, it's mostly a description and a call out for your task. So here, you can see this is an example. This is not one from the course. This is just an example for you to look at. The instructions are to add a method to the class. There's some description here at the top. There might be pictures or example code like we see here. And eventually, you'll get to a section called your task. And this tells you what you need to do to solve the challenge. In this case, you want to create the DoWork method in the example class. So over here in your code, you can see there's already an example class that has an existing method. You need to create the DoWork method over here and then that DoWork method. Return type is a Int32. There's also a hint at the bottom. If you want to learn more, you can click on this link to go to the attributes course on LinkedIn learning. Once you've entered your code on the right side of the screen, you can click the test my code button. This will compile your code, start up a virtual machine and start running your code. In this case, you can see the output over here. It says something isn't working. And if you want more information, you can see this help section. You can set the show expected result to true to see the correct value, and you can set show hints to True to see a hint. Now where do you find those? Those are in this class called Answer and they're both set defaults by default. So let's change show expected result to true and retest the code. Now you're starting to see some information. It says, here's a list of the example class methods. There is a validate check sum method. Yes, that returns a Boolean, but there is no due work method. And at the bottom, you can see the test failed. The example class does not implement the due work method. You can also get hints by turning on this Boolean or saying this to true, I should say, retest. And now you can see there's also a hint and of course the hints will be, will vary depending on the challenge. This one just says try adding the DoWork method to the example class. So, let's do that. I'll go over here and I'll create a public method. Now you get all the intelligence that you expect in a modern editor. If I did the controlled space bar here I can see a list of possible words I can have auto-complete. What I want to do is do public void, do work, test my code again. Now I see the results that there are two methods, validate checksum and DoWork, which is returning void. And now the test failed says the DoWork method does not return system.Int32. So, I'll change this to return system.Int32. I'll do a control space bar. I get a dropdown list. I'll choose Int32 here and then press tab. Like I said, it works like similar to your other IDs and of course, it's missing something. This needs to be a capital S. You see, I get a red squiggle. If I try to run this now, you can see there's red squiggle here that's telling me that not all code pass return of value. And if I insist on testing my code, I'll see that there's an error shown up here in the cons output. So let's fix this by returning a value and now, we have a success message. Let's talk about the test code. Most of the examples in this course are using reflection including this simple example that I'm using to show how CoderPad works. I've written some unit tests that get the methods on the example class, and then I'll go and look for the DoWork method and I'll check for the correct return type. Most of the examples, or I should say most of the challenges in this course, the test code is very simple. You don't see a lot here. There's a lot happening in the unit tests that you can't see. But what I'm showing you here in the test code is a simple is some simple code that might kind of represent what type of code might be called. And I typically will also write out some information here. Your code is tested using .NET Reflection and then there'll be some details of what the test code is verifying. So that's how CoderPad works and the general idea how I've structured the code challenges. When you finished the code challenge, you want to return to the course table of contents and click on the next video to see my solution for each challenge.

内容