Add element to list before specific element
c#, list
Solution
First you could find the index of your item using `FindIndex` method:
var index = myList.FindIndex(x => x.value == "myvalue");
Then `Insert` at the right point:
myList.Insert(index,newItem);
Note that inserting at a given index pushes everything else forward (think about finding your item at index 0).
Problem
I have a list of items, lets say 100 items. I need to add another element before the existing element that matches my condition. What is the fastest way and the most performance optimized to do this? ie.: ``` foreach (var i in myList) { if (myList[i].value == "myValue") { myList[i-1] add ("someOtherValue") } } ``` Maybe i should use other container?