well im no expert
i spent some time attempting to do this using linq but couldn't find a way
at the end of my efforts i think
your original solution is better
if its over a network there are other considerations though
i did find a excellent linq reference page though
http://code.msdn.microsoft.com/101-L...mples-3fb9811b
on further thought a delete is a request
rather then a query so it sort of makes sense
not to be able to do so within a query
maybe in the first place just query all non or delete-able items
and remove any sort of delete button when they are worked on
the real pain is that the enumerable changes when you perform a deleteCode:static void Main(string[] args) { Program I = new Program(); I.TestLinq01(); } public void TestLinq01() { listOfuInts = new List<uint>{ 1, 2, 3, 4, 5 }; ListToConsole("via linq before", listOfuInts); var query = // var is of type ienumerable from linq from n in listOfuInts // loop where n != specialValue // conditional select n; // action listOfuInts = query.ToList<uint>(); // convert back to uint ListToConsole("after", listOfuInts); } public void ListToConsole<T>(string msg,List<T> list) { Console.WriteLine(Environment.NewLine + msg); foreach (var obj in list) { Console.WriteLine(obj); } Console.WriteLine(Environment.NewLine); }
this was my looping solution for a delete all but special values
in truth i don't really use linq much i find it far more difficult
then just straight coding something
but linq is more for querys so...Code:// remove all not with a special value public void TestLoop02() { listOfuInts = new List<uint> { 1, 2, 3, 4, 5 }; ListToConsole("via loop02 before", listOfuInts); int index = 0; while (index < listOfuInts.Count) { if (listOfuInts.ElementAt(index) != specialValue) { listOfuInts.RemoveAt(index); } else { index++; } } ListToConsole("via loop02 after remaining values not removed", listOfuInts); }




Reply With Quote
