Alright, this is the exercise:
Set a struct called “Date” that contains date, including: year, month and day. Also, define a class called “Phone” that contains a name, number, date of birth and address. Need to create an array that contains objects of type Phone and sort them by name, number, and date.
This is my code:
struct Date
{
int year, month, day;
public Date(int year, int month, int day)
{
this.year = year;
this.month = month;
this.day = day;
}
}
class Phone
{
int number;
string birthday, adress, name;
public Phone(int number, string birthday, string adress, string name)
{
this.number = number;
this.birthday = birthday;
this.adress = adress;
this.name = name;
}
}
class Program
{
static void Main(string[] args)
{
Phone[] p = new Phone[3];
for (int i = 0; i < p.Length; i++)
{
}
}
}
So, the thing is that I don’t know how to get the struct date from the “Phone” class.
It suppose to be something like this right? birthday.year, and such.
Thanks.
You’ve declared
birthdayas astring.You need to declare it as a
Date.