Je suis novice en tant que déléguée (en anglais aussi).Action C#, Func, Peut être imbriqué ou chaîné?
Ceci est mon exemple de code:
var expected_for = new int[Length];
Func<int[], Action<int>> opFactory = res => i => res[i] = arg1[i] + arg2[i];
Parallel.For(0, arg1.Length, opFactory(expected)); // working well
Enumerable.Range(0, arg1.Length).ToList().ForEach(opFactory(expected_foreach)); // working well
for (int i = 0; i < arg1.Length; i++)
{
opFactory(expected_for); //No Error, but expected_for is not changed
}
Q1. Func<int[], Action<int>> opFactory = res => i => res[i] = arg1[i] + arg2[i];
dans Func
, Action
peut être imbriqué? C'est trop difficile à comprendre pour moi.
Q2. Le troisième argument de Parallel.For
requiert Action
. Puis ma ligne Func
était Action
?
Q3. Comment puis-je enregistrer la valeur dans for()
?
Merci de lire
Cordialement
ICE
au sujet Q3, j'ai trouvé la solution "opFactory (expected_for) (i)" – Icetiger