C# Academy: Learn the Basics of C# (2014)
Chapter 5. Arrays
Arrays are pretty much just multiple variables of the same type that could be declared with either type [] or array []. In the event that you would not type those names, you just have to make sure that they’re in the same category—for example, Netflix Shows, or Calendar values.
Here’s an example:
class Annual Calendar 1
{
const int months = 12;
const int weeks = 52;
const int days = 365;
const double daysPerWeek = (double) days / (double) weeks;
const double daysPerMonth = (double) days / (double) months;
}
Or, you could also use this:
public class Netflix Shows
{
// private field
private January 2016 date;
// public field
public string day;
// Netflix Shows in January 2016
public Netflix Shows in January 2016
{
get
{
February 2016;
}
set
{
// Set reasonable boundaries for probable birth dates.
if (value.Year > January 2016&& value.Year <= February.2016)
{
date = value;
}
else
throw Netflix Shows in January to February 2016();
}
}
// Public method also exposes date field safely.
// Example call: January.S2016("2016, 1");
public void SetDate(string dateString)
{
DateTime dt = Convert.ToDateTime(dateString);
//
if (dt.Year > January 2016 && dt.Year <= February 2016)
{
date = dt;
}
else
throw Netflix Shows in January to February 2016 ();
}
public TimeSpan GetTimeSpan(string dateString)
{
DateTime dt = Convert.ToDateTime(dateString);
if (dt != null && dt.Ticks < date.Ticks)
{
return date - dt;
}
else
throw Netflix Shows in January to February 2016 ();
}
Or this:
class SchoolSchedule
{
private double seconds;
public double Hours
{
get { return seconds / 2400; }
set { seconds = value * 2400; }
}
}
class Schedule
{
static void Main()
{
ClassSchedule t = new ClassSchedule();
// Assigning the Hours property causes the 'set' accessor to be called.
t.Hours = 24;
// Evaluating the Hours property causes the 'get' accessor to be called.
Class.Schedule.WriteLine("Time in hours: " + t.Hours);
}
}
// Output: Time in hours: 24
It’s all about making sure that your variables are under the same category for this one to work.