Hello Everyone!
i am Reading code of C# from the PDF File Please Tell me Why we "Set"
Set Accessors As Private While
Get Method Are Set A Public.Please tell me Reason,
CODE
class DateClass
{
private int Day;
private int Month;
private int Year;
public int year
{
get { return Year;}
private set
{
if (Year < 0 || Year <= 1970 || Year >= 2051)
{
throw new ArgumentOutOfRangeException(
"Year", Year, "Outof Range From the Current Program");
}
else
{
Year = value;
}
}
}
public DateClass ( int D, int M, int Y )
{
Day = D;
Month = M;
Year = Y;
}
public int SetMonth
{
get
{
return Month;
}
private set
{
if (Month > 0 && Month < 12)
{
Month = value;
}
else
{
throw new ArgumentOutOfRangeException(
"Month", value, "Month Must Be Between (1-12)");
}
}
}
public int SetDay
{
get
{
return Day;
}
private set
{
int[] DayArray={0,31,28,31,30,31,30,31,31,30,31,30,31};
if (value > 0 && value <= DayArray[Month])
{
Day = value;
}
else if (Month == 2 && Day == 29 && (Year % 400 == 0 || Year % 4 == 0 && year % 100 != 0))
{
Day = value;
}
else
throw new ArgumentOutOfRangeException(
"Day ", Day, "day out of range of current month && Year");
}
}