C# – Defining Classes Homework from SoftUni – Video

In the current article, I will show you the code of a solution of one homework from the SoftUni (www.softuni.bg). The solution is built in YouTube and you may take a look at it, if you want to hear me speaking in English.

So, here comes the problem:


Define a class Person that has name, age and email. The name and age are mandatory. The email is optional. Define properties that accept non-empty name and age in the range [1…100]. In case of invalid argument, throw an exception. Define a property for the email that accepts either null or non-empty string containing ‘@’. Define two constructors. The first constructor should take name, age and email. The second constructor should take name and age only and call the first constructor. Implement the ToString() method to enable printing persons at the console.

The code:

 

And finally, the video:


Enjoy it!