-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
52 lines (49 loc) · 1.8 KB
/
Copy pathProgram.cs
File metadata and controls
52 lines (49 loc) · 1.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace _3.Exceptions
{
class Program
{
static void Main()
{
DateTime t = DateTime.Now;
Console.WriteLine(t);
InvalidRangeException<int> someIntExeption =
new InvalidRangeException<int>("The have to enter a number in the range from 0 do 100!",1,100);
Console.WriteLine("Enter 5 numbers from 0 do 100:");
for (int i = 0; i < 5; i++)
{
int number = int.Parse(Console.ReadLine());
if (number<someIntExeption.Start|| number>someIntExeption.End)
{
throw someIntExeption;
}
else
{
Console.WriteLine("The number is correct!");
}
}
string startDate="1/1/1980";
string endDate="1/1/2013";
InvalidRangeException<DateTime> someDateExpection =
new InvalidRangeException<DateTime>("The date isn't in the correct range from 1980 to 2013!"
,DateTime.Parse(startDate),DateTime.Parse(endDate));
Console.WriteLine("Enter 5 dates in the specified format: dd.mm.yyyy!(from 1980 to 2013)");
for (int i = 0; i < 5; i++)
{
string date = Console.ReadLine();
DateTime someDate = DateTime.Parse(date);
if (someDate.Year<someDateExpection.Start.Year || someDate.Year>someDateExpection.End.Year)
{
throw someDateExpection;
}
else
{
Console.WriteLine("The date is correct!");
}
}
}
}
}