Can I used IComparable Interface for struct?

Posted by Sunitajadhav under C# on 12/17/2009 | Views : 139227 | Status : [Member] | Replies : 1
Hello friends,
I have to sort array list which contains struct object.I am giving code here.can i use IComparable interface for struct to sort the list.
Tell me this is right which i have done.My code is working fine.


struct ScheduleReportStruct:IComparable
{
public string m_ProjectName;
public int m_ScheduleCnt;
public ArrayList m_ResourceInfoList;
public ArrayList m_ScheduleList;
public float m_MakeSpan;
public int CompareTo(object obj)
{
ScheduleReportStruct t_ScheduleReportStruct;
t_ScheduleReportStruct = (ScheduleReportStruct)obj;
return m_MakeSpan.CompareTo(t_ScheduleReportStruct.m_MakeSpan);
}
}

ScheduleReportStruct t_ScheduleReportStruct=new ScheduleReportStruct();

myProjectlist.Add(ScheduleReportStruct);
myProjectlist.sort();


Thanks




Responses

Posted by: Lakhangarg on: 12/18/2009 [Member] [Moderator] Silver

Up
0
Down
Hi Sunita-

Please Check this Link:
http://www.csharphelp.com/2007/07/custom-shortdate-type-struct-icomparable/

Thanks & Regards
Lakhan Pal Garg

Sunitajadhav, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response