Answer the question
In order to leave comments, you need to log in
How to implement changing the elements of the input sequence using the PLINQ ForAll(Action) extension method?
I can't figure out how to modify the elements of the input sequence using the ForAll(lamda) extension method.
Let's say we have an array:
string[] lines = { "max9", "cat", " joe", "line", "jgeg9nj", "ergeg",
"egerg", "egreg4g", "29fweggf", "wfw99efyopkb" };
lines.AsParallel().Where(l=> l.Contains("9")==true)
.ForAll(l => l+="MARK");
// Убеждаемся что последовательность осталась без изменений, а жаль
foreach (var line in lines)
Console.WriteLine(line);
Console.ReadLine();
Answer the question
In order to leave comments, you need to log in
lines = lines.AsParallel().Select(l => l.Contains("9") ? l + "MARK" : l).ToArray();
Thank you for your attention, but I did not understand how this would help me. By the way, I determined that if you use any other objects as elements of the collection, then there are no problems. For example, this code works correctly:
class cl
{
public string name;
public string city;
public cl(string n, string c)
{
name = n;
city = c;
}
}
List<storage> = new List();
storage.Add(new cl("wfwf","wefwe" ));
storage.Add(new cl("wfwf", "wefwe"));
storage.Add(new cl("wfwf", "wefwe"));
storage.AsParallel().Select(i => i).ForAll(i =>i.name="qq");
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question