I have a problem with the ForEach in an observablecollection. Visual Studio tells me:
"The 'observablecollection' does not contain a 'ForEach' definition and was not found at the 'ForEach' extension method that accepts a first 'observablecollection' type argument. Probably missing a directive using or reference to the assembly".
The problem is that, the similar code in another project, works fine but in this new project not. Where am I wrong?
Thank you
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ProvaBindingXaml
{
/* public class Impiegato
{
public string Nome { get; set; }
public string Cognome { get; set; }
public string Matricola { get; set; }
}
*/
public class Rule
{
public string Ruolo { get; set; }
public Rule(string ruolo)
{
this.Ruolo = ruolo;
}
public override string ToString()
{
return this.Ruolo;
}
public static ObservableCollection<Rule> GetAllRules()
{
var CollectionRuoli = new ObservableCollection<Rule>();
CollectionRuoli.Add(new Rule ("Impiegato"));
CollectionRuoli.Add(new Rule ("Dirigente"));
CollectionRuoli.Add(new Rule ("Operaio"));
CollectionRuoli.Add(new Rule ("Manutentore"));
CollectionRuoli.Add(new Rule ("Presidente"));
return CollectionRuoli;
}
public static void GetComboBoxList(ObservableCollection<Rule> RuleItems)
{
var allItems = GetAllRules();
RuleItems.Clear();
allItems.ForEach(p => RuleItems.Add(p));
}
}
}