Click here to Skip to main content
15,922,894 members
Home / Discussions / C#
   

C#

 
AnswerRe: checking files using c# Pin
Paul Conrad7-Oct-07 5:44
professionalPaul Conrad7-Oct-07 5:44 
QuestionGetting InvalidOperationException when I modify an arraylist Pin
humblepgmr6-Oct-07 19:51
humblepgmr6-Oct-07 19:51 
AnswerRe: Getting InvalidOperationException when I modify an arraylist Pin
Luc Pattyn6-Oct-07 20:24
sitebuilderLuc Pattyn6-Oct-07 20:24 
AnswerRe: Getting InvalidOperationException when I modify an arraylist Pin
Matthew Cuba7-Oct-07 10:33
Matthew Cuba7-Oct-07 10:33 
AnswerRe: How do you sort an ArrayList of customObjects? Pin
Dave Kreskowiak6-Oct-07 15:49
mveDave Kreskowiak6-Oct-07 15:49 
GeneralRe: How do you sort an ArrayList of customObjects? Pin
Pete O'Hanlon7-Oct-07 10:34
mvePete O'Hanlon7-Oct-07 10:34 
GeneralRe: How do you sort an ArrayList of customObjects? Pin
Dave Kreskowiak7-Oct-07 15:52
mveDave Kreskowiak7-Oct-07 15:52 
QuestionSemi-Random Array Sorting Pin
BaraMustafa6-Oct-07 15:10
BaraMustafa6-Oct-07 15:10 
I have an class defined as below. This class has an integer value assigned to it named initiative. For the purposes of this post this value can be from 1 to 3.

<br />
public class Unit : IComparable<br />
{<br />
    ....<br />
    public int Initiative = ....;<br />
<br />
    public int CompareTo(object obj)<br />
    {<br />
        if (obj is Unit)<br />
        {<br />
            Unit u = (Unit)obj;<br />
            return Initiative.CompareTo(u.Initiative);<br />
        }<br />
        throw new ArgumentException("object is not a Unit");    <br />
    }<br />
}<br />


I have 10 of these objects defined in an array. I want to be able to sort the array by this initiative value however everytime I run a sort I want the object with equal value to be randomly organised. For example if I run sort once:

object - initiative
A - 1
B - 1
C - 1
D - 2
E - 2
F - 2
G - 3
H - 3
I - 3
J - 3

If I run it again, I may get:

object - initiative
B - 1
A - 1
C - 1
F - 2
D - 2
E - 2
G - 3
J - 3
H - 3
I - 3

How can I achieve this using IComparable?

Thanks in advance.
AnswerRe: Semi-Random Array Sorting Pin
Christian Graus6-Oct-07 15:31
protectorChristian Graus6-Oct-07 15:31 
GeneralRe: Semi-Random Array Sorting Pin
Lutosław6-Oct-07 22:09
Lutosław6-Oct-07 22:09 
GeneralRe: Semi-Random Array Sorting Pin
Christian Graus6-Oct-07 23:31
protectorChristian Graus6-Oct-07 23:31 
QuestionPLZ I Want to used xml file as database( how to add,update,delete and Search) Pin
DiefAlla6-Oct-07 13:24
DiefAlla6-Oct-07 13:24 
AnswerRe: PLZ I Want to used xml file as database( how to add,update,delete and Search) [modified] Pin
Dave Kreskowiak6-Oct-07 13:31
mveDave Kreskowiak6-Oct-07 13:31 
GeneralRe: PLZ I Want to used xml file as database( how to add,update,delete and Search) Pin
Christian Graus6-Oct-07 13:49
protectorChristian Graus6-Oct-07 13:49 
GeneralRe: PLZ I Want to used xml file as database( how to add,update,delete and Search) Pin
Dave Kreskowiak6-Oct-07 15:42
mveDave Kreskowiak6-Oct-07 15:42 
AnswerRe: PLZ I Want to used xml file as database( how to add,update,delete and Search) Pin
Christian Graus6-Oct-07 13:33
protectorChristian Graus6-Oct-07 13:33 
AnswerRe: PLZ I Want to used xml file as database( how to add,update,delete and Search) Pin
BAIJUMAX7-Oct-07 5:35
professionalBAIJUMAX7-Oct-07 5:35 
QuestionProblem in deployment urgent Pin
Shuaib wasif khan6-Oct-07 12:36
Shuaib wasif khan6-Oct-07 12:36 
AnswerRe: Problem in deployment urgent Pin
Christian Graus6-Oct-07 13:07
protectorChristian Graus6-Oct-07 13:07 
AnswerRe: Problem in deployment urgent Pin
Paul Conrad7-Oct-07 5:46
professionalPaul Conrad7-Oct-07 5:46 
GeneralRe: Problem in deployment urgent Pin
Pete O'Hanlon7-Oct-07 10:40
mvePete O'Hanlon7-Oct-07 10:40 
GeneralRe: Problem in deployment urgent Pin
Paul Conrad7-Oct-07 11:05
professionalPaul Conrad7-Oct-07 11:05 
QuestionAccess properties from a class not belonging to the namespace Pin
ESTAN6-Oct-07 9:56
ESTAN6-Oct-07 9:56 
AnswerRe: Access properties from a class not belonging to the namespace Pin
Dave Kreskowiak6-Oct-07 13:35
mveDave Kreskowiak6-Oct-07 13:35 
GeneralRe: Access properties from a class not belonging to the namespace Pin
ESTAN6-Oct-07 13:42
ESTAN6-Oct-07 13:42 

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.