C
Chris
Hi,
I try to assign an object of MyDate to an object of Person but don't know
well how ? (see code below)
The way I have implemented it so far will assign a MyDate-object to a new
Person-object, not to an already existing one.
I'm stuck.
Who can help me ?
thnx
Chris
******************************************
class MyDate
{
public int m_day, m_month, m_year;
public MyDate(int d, int m, int y)
{
m_day = d;
m_month = m;
m_year = y;
}
public override string ToString()
{
return m_day + "/" + m_month + "/" + m_year;
}
}
class Person
{
public string m_firstname;
public string m_lastname;
public MyDate m_birthdate;
public Person(string first, string last)
{
m_firstname = first;
m_lastname = last;
}
public Person(MyDate date)
{
m_birthdate = date;
}
public static implicit operator Person(MyDate date)
{
return new Person(date);
}
}
class App
{
public static void Main()
{
MyDate dt = new MyDate(10,10,1970);
Person annie = new Person("Annie", "Janssen");
annie = dt; // will assign to a new object ,NOT to existing one
}
}
I try to assign an object of MyDate to an object of Person but don't know
well how ? (see code below)
The way I have implemented it so far will assign a MyDate-object to a new
Person-object, not to an already existing one.
I'm stuck.
Who can help me ?
thnx
Chris
******************************************
class MyDate
{
public int m_day, m_month, m_year;
public MyDate(int d, int m, int y)
{
m_day = d;
m_month = m;
m_year = y;
}
public override string ToString()
{
return m_day + "/" + m_month + "/" + m_year;
}
}
class Person
{
public string m_firstname;
public string m_lastname;
public MyDate m_birthdate;
public Person(string first, string last)
{
m_firstname = first;
m_lastname = last;
}
public Person(MyDate date)
{
m_birthdate = date;
}
public static implicit operator Person(MyDate date)
{
return new Person(date);
}
}
class App
{
public static void Main()
{
MyDate dt = new MyDate(10,10,1970);
Person annie = new Person("Annie", "Janssen");
annie = dt; // will assign to a new object ,NOT to existing one
}
}