Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
School/C# - Beginner (Denis)/Lesson 46/lesson_46.cs
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
123 lines (118 sloc)
2.42 KB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
try | |
{ | |
Person p = new Person { Name = "Tom", Age = 17 }; | |
} | |
catch (Exception ex) | |
{ | |
Console.WriteLine($"Ошибка: {ex.Message}"); | |
} | |
Console.Read(); | |
} | |
} | |
class Person | |
{ | |
private int age; | |
public string Name { get; set; } | |
public int Age | |
{ | |
get { return age; } | |
set | |
{ | |
if (value < 18) | |
{ | |
throw new Exception("Лицам до 18 регистрация запрещена"); | |
} | |
else | |
{ | |
age = value; | |
} | |
} | |
} | |
} | |
class PersonException : Exception | |
{ | |
public PersonException(string message) | |
: base(message) | |
{ } | |
} | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
try | |
{ | |
Person p = new Person { Name = "Tom", Age = 17 }; | |
} | |
catch (PersonException ex) | |
{ | |
Console.WriteLine("Ошибка: " + ex.Message); | |
} | |
Console.Read(); | |
} | |
} | |
class Person | |
{ | |
private int age; | |
public int Age | |
{ | |
get { return age; } | |
set | |
{ | |
if (value < 18) | |
throw new PersonException("Лицам до 18 регистрация запрещена"); | |
else | |
age = value; | |
} | |
} | |
} | |
class PersonException : ArgumentException | |
{ | |
public PersonException(string message) | |
: base(message) | |
{ } | |
} | |
class PersonException : ArgumentException | |
{ | |
public int Value { get; } | |
public PersonException(string message, int val) | |
: base(message) | |
{ | |
Value = val; | |
} | |
} | |
class Person | |
{ | |
public string Name { get; set; } | |
private int age; | |
public int Age | |
{ | |
get { return age; } | |
set | |
{ | |
if (value < 18) | |
throw new PersonException("Лицам до 18 регистрация запрещена", value); | |
else | |
age = value; | |
} | |
} | |
} | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
try | |
{ | |
Person p = new Person { Name = "Tom", Age = 13 }; | |
} | |
catch (PersonException ex) | |
{ | |
Console.WriteLine($"Ошибка: {ex.Message}"); | |
Console.WriteLine($"Некорректное значение: {ex.Value}"); | |
} | |
Console.Read(); | |
} | |
} |