https://pastein.ru/t/7r
скопируйте уникальную ссылку для отправки
using System;
using System.Runtime.InteropServices;
namespace Lab_1
{
class Program
{
enum Months
{
January = 1, February, March, April, May, June, July, August, September, October, November, December
}
class Date
{
public Date()
{
this.month = Months.January;
this.day = 1;
this.year = 1;
}
public Date(int dayDate, int monthDate, int yearDate)
{
this.month = (Months)Enum.ToObject(typeof(Months), monthDate);
this.day = dayDate;
this.year = yearDate;
}
private int day;
public int D
{
get
{
return day;
}
set
{
if (((value < 1 || value > 31)
&& (this.month == Months.January || this.month == Months.March || this.month == Months.May ||
this.month == Months.July || this.month == Months.August || this.month == Months.October || this.month == Months.December)) ||
((value < 1 || value > 30) && (this.month == Months.April || this.month == Months.June || this.month == Months.September || this.month == Months.November)) ||
((value < 1 || value > 29) && this.month == Months.February))
throw new Exception("Not a valid type of day");
else
{
day = value;
}
}
}
private Months month;
public Months M
{
get
{
return month;
}
set
{
if (value < Months.January || value > Months.December)
throw new Exception("Not a valid type of month");
else
{
month = (Months)Enum.ToObject(typeof(Months), value);
}
}
}
private int year;
public int Y
{
get
{
return year;
}
set
{
if (year < 0 || year > int.MaxValue)
throw new Exception("Not a valit type of year");
else
{
year = value;
}
}
}
public void consoleOutput()
{
Console.WriteLine($"Current date: {this.day}.{(int)this.month}.{this.year}");
}
}
static void Main(string[] args)
{
byte b = new byte();
int i = new int();
short sh = new short();
//string str = new string("0");
sbyte sb = new sbyte();
ushort ush = new ushort();
uint ui = new uint();
long l = new long();
ulong ul = new ulong();
char ch = new char();
float fl = new float();
double doub = new double();
decimal dec = new decimal();
int bs = Marshal.SizeOf(b), iss = Marshal.SizeOf(i), shs = Marshal.SizeOf(sh),
/*strs = Marshal.SizeOf<string>(str),*/ sbs = Marshal.SizeOf(sb), ushs = Marshal.SizeOf(ush),
uis = Marshal.SizeOf(ui), ls = Marshal.SizeOf(l), uls = Marshal.SizeOf(ul), chs = Marshal.SizeOf(ch),
fls = Marshal.SizeOf(fl), doubs = Marshal.SizeOf(doub), decs = Marshal.SizeOf(dec);
Console.WriteLine("--------Table of sizes of types in C#--------");
Console.WriteLine($"BYTE-----------------{bs}-------From ({byte.MinValue}) to ({byte.MaxValue})");
Console.WriteLine($"INT------------------{iss}-------From ({int.MinValue}) to ({int.MaxValue})");
Console.WriteLine($"SHORT----------------{shs}-------From ({short.MinValue}) to ({short.MaxValue})");
Console.WriteLine($"SBYTE----------------{sbs}-------From ({sbyte.MinValue}) to ({sbyte.MaxValue})");
Console.WriteLine($"USHORT---------------{ushs}-------From ({ushort.MinValue}) to ({ushort.MaxValue})");
Console.WriteLine($"UINT-----------------{uis}-------From ({uint.MinValue}) to ({uint.MaxValue})");
Console.WriteLine($"LONG-----------------{ls}-------From ({long.MinValue}) to ({long.MaxValue})");
Console.WriteLine($"ULONG----------------{uls}-------From ({ulong.MinValue}) to ({ulong.MaxValue})");
Console.WriteLine($"CHAR-----------------{chs}-------From ({char.MinValue}) to ({char.MaxValue})");
Console.WriteLine($"FLOAT----------------{fls}-------From ({float.MinValue}) to ({float.MaxValue})");
Console.WriteLine($"DOUBLE---------------{doubs}-------From ({double.MinValue}) to ({double.MaxValue})");
Console.WriteLine($"DECIMAL--------------{decs}------From ({decimal.MinValue}) to ({decimal.MaxValue})");
Console.WriteLine("\n\n");
float[] arr = new float[] { 3.5F, 7.3F, 5.5F, 3.2F };
Console.Write("The containment of the float[] array: ");
foreach (float a in arr)
{
Console.Write($"{a} ");
}
Console.WriteLine("\n\n");
Date date1 = new Date();
try
{
date1.M = (Months)7;
}
catch (Exception ex)
{
Console.WriteLine($"{ex.Message}");
Console.WriteLine($"{ex.Data}");
}
try
{
date1.D = 16;
}
catch (Exception ex)
{
Console.WriteLine($"{ex.Message}");
Console.WriteLine($"{ex.Data}");
}
try
{
date1.Y = 2001;
}
catch (Exception ex)
{
Console.WriteLine($"{ex.Message}");
Console.WriteLine($"{ex.Data}");
}
date1.consoleOutput();
Console.ReadKey();
}
}
}