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

C#

 
AnswerRe: How to set up Winforms app to avoid piracy? Pin
Not Active10-Dec-11 6:07
mentorNot Active10-Dec-11 6:07 
AnswerRe: How to set up Winforms app to avoid piracy? Pin
PIEBALDconsult10-Dec-11 8:21
mvePIEBALDconsult10-Dec-11 8:21 
AnswerRe: How to set up Winforms app to avoid piracy? Pin
Eddy Vluggen10-Dec-11 13:16
professionalEddy Vluggen10-Dec-11 13:16 
GeneralRe: How to set up Winforms app to avoid piracy? Pin
Addy Tas11-Dec-11 1:49
Addy Tas11-Dec-11 1:49 
GeneralRe: How to set up Winforms app to avoid piracy? Pin
Eddy Vluggen11-Dec-11 12:27
professionalEddy Vluggen11-Dec-11 12:27 
QuestionCall to REST WCF service creating a file instead of string Pin
nitin_ion10-Dec-11 1:09
nitin_ion10-Dec-11 1:09 
AnswerRe: Call to REST WCF service creating a file instead of string Pin
Richard MacCutchan10-Dec-11 2:54
mveRichard MacCutchan10-Dec-11 2:54 
Question8 queens in c# Pin
Member 84662349-Dec-11 21:34
Member 84662349-Dec-11 21:34 
AnswerRe: 8 queens in c# PinPopular
Luc Pattyn10-Dec-11 0:15
sitebuilderLuc Pattyn10-Dec-11 0:15 
GeneralRe: 8 queens in c# Pin
Member 846623410-Dec-11 14:04
Member 846623410-Dec-11 14:04 
AnswerRe: 8 queens in c# Pin
Luc Pattyn10-Dec-11 14:29
sitebuilderLuc Pattyn10-Dec-11 14:29 
GeneralRe: 8 queens in c# Pin
Member 846623410-Dec-11 15:31
Member 846623410-Dec-11 15:31 
AnswerRe: 8 queens in c# Pin
Luc Pattyn10-Dec-11 22:10
sitebuilderLuc Pattyn10-Dec-11 22:10 
AnswerRe: 8 queens in c# Pin
PIEBALDconsult10-Dec-11 2:46
mvePIEBALDconsult10-Dec-11 2:46 
QuestionTimezone parsing issue - "Date" is wrong (but offset in terms of hours/minutes correct) Pin
devvvy8-Dec-11 17:06
devvvy8-Dec-11 17:06 
AnswerRe: Timezone parsing issue - "Date" is wrong (but offset in terms of hours/minutes correct) Pin
Richard MacCutchan8-Dec-11 22:28
mveRichard MacCutchan8-Dec-11 22:28 
AnswerRe: Timezone parsing issue - "Date" is wrong (but offset in terms of hours/minutes correct) Pin
jschell9-Dec-11 11:23
jschell9-Dec-11 11:23 
QuestionList<T>.Sort(IComparer) throws ArgumentException Pin
Firo Atrum Ventus8-Dec-11 15:42
Firo Atrum Ventus8-Dec-11 15:42 
I have a List<> of ShipSprite (a struct). I need to "sort" that list very often. But every once in a while, it Throws this Exception:
ArgumentException.Message:
IComparer (or the IComparable methods it relies upon) did not return zero when Array.Sort called x. CompareTo(x). x: '' x's type: 'ShipSprite' The IComparer: 'ChangeDBLOL.ShipSpriteComparer'.


Here is the code for the IComparer.Compare method:
int IComparer<ShipSprite>.Compare(ShipSprite x, ShipSprite y)
{
    if (!(x.Confirmed ^ y.Confirmed))
    {
        if (x.State == y.State)
        {
            if (x.TA == y.TA)
            {
                if (x.Equals(y)) {
                    return 0; //It's the same ShipSprite, return 0
                }
                else {
                    int res = Utils.r.Next(2) == 0 ? 1 : -1;//OK, It's safe, Random!
                    return res;
                }
            }
            else
            {
                return x.TA.CompareTo(y.TA);
            }
        }
        else
        {
            return x.State.CompareTo(y.State);
        }
    }
    if (x.Confirmed) return -1;
    if (y.Confirmed) return 1;
    return 0x1Dead;
}


Just to be clear, I use this code for testing:
List<ShipSprite> sort = new List<ShipSprite>(sprites);
int k = 0;
StringBuilder sb = new StringBuilder();
while (true)
{
    sb.AppendLine((k++).ToString());
    sort.Sort(new ShipSpriteComparer());
    sb.AppendLine("~~~~~Result list~~~~~");
    foreach (ShipSprite s in sort)
    {
        sb.AppendLine(s.ToString());
    }

}


What bugs me is that this exception only occurs once every 25~40 sort. Do you guys have any idea of what might be the problem?
Oxfords English < Official CCC Players Dictionary

Excuse me for my improper grammar and typos.
It's because English is my primary language, not my first language.

My first languages are C# and Java.
VB, ASP, JS, PHP and SQL are my second language.
Indonesian came as my third language.
My fourth language? I'm still creating it, I'll let you know when it's done! Big Grin | :-D


modified 8-Dec-11 22:14pm.

AnswerRe: List.Sort(IComparer) throws ArgumentException Pin
PIEBALDconsult8-Dec-11 16:06
mvePIEBALDconsult8-Dec-11 16:06 
GeneralRe: List.Sort(IComparer) throws ArgumentException Pin
Firo Atrum Ventus8-Dec-11 16:19
Firo Atrum Ventus8-Dec-11 16:19 
AnswerRe: List.Sort(IComparer) throws ArgumentException Pin
Luc Pattyn8-Dec-11 22:02
sitebuilderLuc Pattyn8-Dec-11 22:02 
GeneralRe: List.Sort(IComparer) throws ArgumentException Pin
Firo Atrum Ventus9-Dec-11 4:58
Firo Atrum Ventus9-Dec-11 4:58 
AnswerRe: List.Sort(IComparer) throws ArgumentException Pin
BobJanova8-Dec-11 22:37
BobJanova8-Dec-11 22:37 
GeneralRe: List.Sort(IComparer) throws ArgumentException Pin
Firo Atrum Ventus9-Dec-11 5:07
Firo Atrum Ventus9-Dec-11 5:07 
QuestionPorting VS 2005 => 2010: "Could not load file or assembly..." [SOLVED] Pin
Alan Balkany8-Dec-11 12:14
Alan Balkany8-Dec-11 12:14 

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.