Click here to Skip to main content
15,887,746 members
Home / Discussions / C#
   

C#

 
AnswerRe: Sql Transactions Pin
PIEBALDconsult2-Aug-08 5:24
mvePIEBALDconsult2-Aug-08 5:24 
QuestionHow to forbid a control to get focus ? Pin
xu_xuthus1-Aug-08 23:55
xu_xuthus1-Aug-08 23:55 
AnswerRe: How to forbid a control to get focus ? Pin
PIEBALDconsult2-Aug-08 5:18
mvePIEBALDconsult2-Aug-08 5:18 
AnswerRe: How to forbid a control to get focus ? Pin
nelsonpaixao3-Aug-08 14:57
nelsonpaixao3-Aug-08 14:57 
QuestionNHibernate Pin
Puneet Bhatnagar1-Aug-08 23:18
Puneet Bhatnagar1-Aug-08 23:18 
AnswerRe: NHibernate Pin
Paul Conrad2-Aug-08 18:56
professionalPaul Conrad2-Aug-08 18:56 
QuestionCollections and sorting using an interface Pin
DaveyM691-Aug-08 21:55
professionalDaveyM691-Aug-08 21:55 
AnswerRe: Collections and sorting using an interface Pin
User 66581-Aug-08 22:56
User 66581-Aug-08 22:56 
The solution depends on how you sort the SpareParts and ServiceTools.

One solution would be to add both collections to a single collection and then sort using a delegate, like this:

private static int CompareStockItems(IStockItem x, IStockItem y)
{
                // add your sorting algorithm here
    if (x.StockCode.Length < y.StockCode.Length)
        return -1;
    else if (x.StockCode.Length > y.StockCode.Length)
        return 1;
    else
        return 0;
}


List<IStockItem> items = new List<IStockItem>();
items.AddRange(sparePartCollection);
items.AddRange(serviceToolCollection);
items.Sort(CompareStockItems);


You can also just do items.Sort() without specifying a sorting delegate, then the CompareTo methods of the two classes will be used.

This however depends on the implementation of the CompareTo method. If you want SpareParts only to be compared between themselves and ServiceTools also only between ServiceTools, then both CompareTo methods are likely to be different and you'd have to use a delegate to sort them in the list.

If the comparison is the same for both stock item types though, then you can duplicate the CompareTo method in both implementations and use something like:

public int CompareTo(object obj)
{
    IStockItem item = obj as IStockItem;
    if (item == null)
        return -1;
    else
    {
        if (this.StockCode.Length < item.StockCode.Length)
            return -1;
        else if (this.StockCode.Length > item.StockCode.Length)
            return 1;
        else
            return 0;
    }
}


for both stock item implementations. I don't recommend this design though, as a change in one implementation needs to be changed in the other accordingly.


regards

modified 12-Sep-18 21:01pm.

GeneralRe: Collections and sorting using an interface Pin
DaveyM692-Aug-08 2:29
professionalDaveyM692-Aug-08 2:29 
GeneralRe: Collections and sorting using an interface Pin
DaveyM692-Aug-08 4:11
professionalDaveyM692-Aug-08 4:11 
GeneralRe: Collections and sorting using an interface Pin
DaveyM692-Aug-08 4:48
professionalDaveyM692-Aug-08 4:48 
GeneralRe: Collections and sorting using an interface [modified] Pin
User 66582-Aug-08 5:06
User 66582-Aug-08 5:06 
GeneralRe: Collections and sorting using an interface Pin
DaveyM692-Aug-08 8:47
professionalDaveyM692-Aug-08 8:47 
GeneralRe: Collections and sorting using an interface Pin
DaveyM692-Aug-08 10:22
professionalDaveyM692-Aug-08 10:22 
Questionmeta file using C# Pin
algates00271-Aug-08 18:56
algates00271-Aug-08 18:56 
AnswerRe: meta file using C# Pin
Thomas Stockwell2-Aug-08 7:31
professionalThomas Stockwell2-Aug-08 7:31 
QuestionHow to find the Content datatype in a String Pin
K V Sekhar1-Aug-08 18:47
K V Sekhar1-Aug-08 18:47 
AnswerRe: How to find the Content datatype in a String Pin
Rajesh R Subramanian1-Aug-08 20:59
professionalRajesh R Subramanian1-Aug-08 20:59 
AnswerRe: How to find the Content datatype in a String Pin
DaveyM691-Aug-08 21:11
professionalDaveyM691-Aug-08 21:11 
AnswerRe: How to find the Content datatype in a String Pin
Anurag Gandhi1-Aug-08 21:51
professionalAnurag Gandhi1-Aug-08 21:51 
GeneralRe: How to find the Content datatype in a String Pin
K V Sekhar1-Aug-08 23:06
K V Sekhar1-Aug-08 23:06 
GeneralRe: How to find the Content datatype in a String Pin
Guffa1-Aug-08 23:35
Guffa1-Aug-08 23:35 
QuestionThe reason behind the differences of this.Font = fontdialog1.Font and btnTest.Font Pin
Lim Yuxuan1-Aug-08 18:37
Lim Yuxuan1-Aug-08 18:37 
AnswerRe: The reason behind the differences of this.Font = fontdialog1.Font and btnTest.Font Pin
Gideon Engelberth2-Aug-08 2:12
Gideon Engelberth2-Aug-08 2:12 
GeneralRe: The reason behind the differences of this.Font = fontdialog1.Font and btnTest.Font Pin
Lim Yuxuan2-Aug-08 4:56
Lim Yuxuan2-Aug-08 4:56 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.