How to copy List<T> to another List<T>?

  • Thread starter Thread starter Jeff0803
  • Start date Start date
J

Jeff0803

Guest
There's a class like following.

public class Appointment
{
private string m_applicationpath;
private Int32 m_appt_no;
private DateTime m_appt_date;
private DateTime m_appt_time;
private DateTime m_appt_datetime;
private string m_appt_type;
private string m_appt_status;
private Int64 m_patient_id;
private string m_last_name;
private string m_first_name;
private string m_h_phone;
private string m_cell_phone;
#region Properties
public Int32 ApptNo
{
get { return this.m_appt_no; }
set { this.m_appt_no = value; }
}
public DateTime ApptDate
{
get { return this.m_appt_date; }
set { this.m_appt_date = value; }
}
public DateTime ApptTime
{
get { return this.m_appt_time; }
set { this.m_appt_time = value; }
}
public DateTime ApptDateTime
{
get
{
m_appt_datetime = m_appt_date.Date.Add(m_appt_time.TimeOfDay);
return this.m_appt_datetime;
}
set { this.m_appt_datetime = value; }
}
public string ApptType
{
get { return this.m_appt_type; }
set { this.m_appt_type = value; }
}
public string ApptStatus
{
get { return this.m_appt_status; }
set { this.m_appt_status = value; }
}
public Int64 PatientID
{
get { return this.m_patient_id; }
set { this.m_patient_id = value; }
}
public string LastName
{
get { return this.m_last_name; }
set { this.m_last_name = value; }
}
public string FirstName
{
get { return this.m_first_name; }
set { this.m_first_name = value; }
}
public string Homephone
{
get { return this.m_h_phone; }
set { this.m_h_phone = value; }
}
public string CellPhone
{
get { return this.m_cell_phone; }
set { this.m_cell_phone = value; }
}
#endregion
public Appointment(string applicationpath)
{
m_applicationpath = applicationpath;
}
public bool Equals(Appointment comparedobject, AppointmentCompareMode comparemode)
{
string dt1 = "";
string dt2 = "";

if (comparemode == AppointmentCompareMode.All)
{
if (this.ApptNo != comparedobject.ApptNo)
{
WriteLog("Appointment.Equals() : ApptNo is not equal " + Environment.NewLine +
"this.ApptNo = " + this.ApptNo.ToString() + ", comparedobject.ApptNo = " +
comparedobject.ApptNo.ToString());
return (false);
}
}
dt1 = this.ApptDate.ToString("MM/dd/yyyy");
dt2 = comparedobject.ApptDate.ToString("MM/dd/yyyy");
if (!dt1.Equals(dt2, StringComparison.OrdinalIgnoreCase))
{
WriteLog("Appointment.Equals() : ApptDate is not equal " + Environment.NewLine +
"this.ApptDate = " + this.ApptDate.ToString("MM/dd/yyyy") + ", comparedobject.ApptDate = " +
comparedobject.ApptDate.ToString("MM/dd/yyyy"));
return (false);
}
dt1 = this.ApptTime.ToString("hh:mm:ss tt");
dt2 = comparedobject.ApptTime.ToString("hh:mm:ss tt");
if (!dt1.Equals(dt2, StringComparison.OrdinalIgnoreCase))
{
WriteLog("Appointment.Equals() : ApptTime is not equal " + Environment.NewLine +
"this.ApptTime = " + this.ApptDate.ToString("hh:mm:ss tt") + ", comparedobject.ApptTime = " +
comparedobject.ApptTime.ToString("hh:mm:ss tt"));
return (false);
}
if (this.ApptType != comparedobject.ApptType)
{
WriteLog("Appointment.Equals() : ApptType is not equal " + Environment.NewLine +
"this.ApptType = " + this.ApptType + ", comparedobject.ApptType = " +
comparedobject.ApptType);
return (false);
}
if (this.ApptStatus != comparedobject.ApptStatus)
{
WriteLog("Appointment.Equals() : ApptStatus is not equal " + Environment.NewLine +
"this.ApptStatus = " + this.ApptStatus + ", comparedobject.ApptStatus = " +
comparedobject.ApptStatus);
return (false);
}
if (this.PatientID != comparedobject.PatientID)
{
WriteLog("Appointment.Equals() : PatientID is not equal " + Environment.NewLine +
"this.PatientID = " + this.PatientID.ToString() + ", comparedobject.PatientID = " +
comparedobject.PatientID.ToString());
return (false);
}
if (this.LastName != comparedobject.LastName)
{
WriteLog("Appointment.Equals() : LastName is not equal " + Environment.NewLine +
"this.LastName = " + this.LastName + ", comparedobject.LastName = " +
comparedobject.LastName);
return (false);
}
if (this.FirstName != comparedobject.FirstName)
{
WriteLog("Appointment.Equals() : FirstName is not equal " + Environment.NewLine +
"this.FirstName = " + this.FirstName + ", comparedobject.FirstName = " +
comparedobject.FirstName);
return (false);
}
if (this.CellPhone != comparedobject.CellPhone)
{
WriteLog("Appointment.Equals() : CellPhone is not equal " + Environment.NewLine +
"this.CellPhone = " + this.CellPhone + ", comparedobject.CellPhone = " +
comparedobject.CellPhone);
return (false);
}
if (this.Homephone != comparedobject.Homephone)
{
WriteLog("Appointment.Equals() : Homephone is not equal " + Environment.NewLine +
"this.Homephone = " + this.Homephone + ", comparedobject.Homephone = " +
comparedobject.Homephone);
return (false);
}

return (true);

}

//Cannot use CDMrCommon.Instance.WriteLog(), so I create thismethod duplicately
private void WriteLog(string strlog)
{
using (StreamWriter w = File.AppendText(m_applicationpath + @"\Log\" + DateTime.Now.Date.ToString("MMddyyyy") + ".log"))
{
w.WriteLine(DateTime.Now.ToLongTimeString() + "\t" + strlog);
}
}
}

And I defined a list like following.


List<Appointment> oldappointmentlist = new List<Appointment>();

List<Appointment> newappointmentlist = new List<Appointment>();


I'd like to copy newappointmentlist to oldappointmentlist.

How to do this?

Continue reading...
 
Back
Top