Click here to Skip to main content
15,891,864 members
Home / Discussions / C#
   

C#

 
GeneralRe: "Configuration system failed to initialize" Pin
AshwiniSH24-Apr-14 21:51
professionalAshwiniSH24-Apr-14 21:51 
Questionhow to use events using Base class Pin
Member 1034709222-Apr-14 15:44
Member 1034709222-Apr-14 15:44 
AnswerRe: how to use events using Base class Pin
Eddy Vluggen23-Apr-14 0:32
professionalEddy Vluggen23-Apr-14 0:32 
QuestionRe: how to use events using Base class Pin
Eddy Vluggen23-Apr-14 5:11
professionalEddy Vluggen23-Apr-14 5:11 
AnswerRe: how to use events using Base class Pin
Marco Bertschi23-Apr-14 5:40
protectorMarco Bertschi23-Apr-14 5:40 
QuestionRetaining index of an item Pin
Chris Copeland22-Apr-14 12:47
mveChris Copeland22-Apr-14 12:47 
AnswerRe: Retaining index of an item Pin
Ravi Bhavnani22-Apr-14 19:24
professionalRavi Bhavnani22-Apr-14 19:24 
GeneralRe: Retaining index of an item Pin
Chris Copeland22-Apr-14 23:11
mveChris Copeland22-Apr-14 23:11 
I believe an issue with using IndexOf is that if the same item is added more than once to the collection, the value returned by IndexOf will be the first index only.

The item I'm storing in the collection could be added multiple times. For instance:

public class MyClass
{
    public string Text { get; set; }
    public int Index { get; set; }
};

private void ExampleList()
{
    // create the list
    List<MyClass> list = new List<MyClass>();

    // create an instance
    MyClass first = new MyClass() { Text = "Hello" };

    // append this item into the list twice
    list.Add(first);
    list.Add(first);

    // create a second instance
    MyClass second = new MyClass() { Text = "Goodbye" };

    // append this item into the list
    list.Add(second);

    // if the Index property were to use the IndexOf method from the parent list,
    // below would be the results:
    System.Diagnostics.Debug.WriteLine(list[0].Index); // 0
    System.Diagnostics.Debug.WriteLine(list[1].Index); // 0
    System.Diagnostics.Debug.WriteLine(list[2].Index); // 1
}


Obviously if multiple instances of the same object is going to be an issue, I could re-factor my code to prevent multiple additions, but it'd be preferable if the developer had the option to add the same item twice.

Otherwise, am I restricted entirely to updating the Index property on each collection change? I just wondered if there was some work-around (ie, creating an index array or using some sort of indexing engine built into the framework.)

Thanks
GeneralRe: Retaining index of an item Pin
Eddy Vluggen23-Apr-14 0:30
professionalEddy Vluggen23-Apr-14 0:30 
GeneralRe: Retaining index of an item Pin
Chris Copeland23-Apr-14 1:55
mveChris Copeland23-Apr-14 1:55 
GeneralRe: Retaining index of an item Pin
Ravi Bhavnani23-Apr-14 2:48
professionalRavi Bhavnani23-Apr-14 2:48 
AnswerRe: Retaining index of an item Pin
Marco Bertschi22-Apr-14 22:29
protectorMarco Bertschi22-Apr-14 22:29 
Questionwhich Data Grid to use?? Pin
Member 1076709622-Apr-14 6:50
Member 1076709622-Apr-14 6:50 
AnswerRe: which Data Grid to use?? Pin
OriginalGriff22-Apr-14 8:27
mveOriginalGriff22-Apr-14 8:27 
GeneralRe: which Data Grid to use?? Pin
Member 1076709622-Apr-14 21:45
Member 1076709622-Apr-14 21:45 
AnswerRe: which Data Grid to use?? Pin
Rahul VB22-Apr-14 9:02
professionalRahul VB22-Apr-14 9:02 
AnswerRe: which Data Grid to use?? Pin
Wes Aday22-Apr-14 13:19
professionalWes Aday22-Apr-14 13:19 
GeneralRe: which Data Grid to use?? Pin
Mycroft Holmes22-Apr-14 14:06
professionalMycroft Holmes22-Apr-14 14:06 
GeneralRe: which Data Grid to use?? Pin
Member 1076709622-Apr-14 14:39
Member 1076709622-Apr-14 14:39 
AnswerRe: which Data Grid to use?? Pin
thatraja22-Apr-14 22:16
professionalthatraja22-Apr-14 22:16 
Questionmicrosoft.office.interop.word compatibility Pin
Member 980950622-Apr-14 4:42
Member 980950622-Apr-14 4:42 
AnswerRe: microsoft.office.interop.word compatibility Pin
Eddy Vluggen22-Apr-14 6:51
professionalEddy Vluggen22-Apr-14 6:51 
QuestionLAN Pin
Member 1068496822-Apr-14 0:53
Member 1068496822-Apr-14 0:53 
AnswerRe: LAN Pin
Keith Barrow22-Apr-14 1:05
professionalKeith Barrow22-Apr-14 1:05 
AnswerRe: LAN Pin
Eddy Vluggen22-Apr-14 6:52
professionalEddy Vluggen22-Apr-14 6:52 

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.