Yes, your class needs to implement the IEnumerable
interface. In addition, you have to make the namespace System.Linq
.
You are calling the Pessoas
class. This means that it will contain several people. So it makes sense to implement this interface. But if your intention is that this class represents only one person, then it would not make sense and would have to save the lists of people on another object, perhaps a list, as shown in the answer of the carlosfigueira. If you intend to use a list to save people, then the list already implements IEnumerable
and you only need to use LINQ's namespace . But if it is, the class name gives a wrong indication of what it represents.
Anyway you can not call this method from the class itself, as in the example shown (I think). It has to be done with an instance. It may even be an instance, since C # allows variables to have names that are the same as the types, but the name does not give a good indication of what it is. So you probably want a var pessoas = new List<Pessoa>();
.
How LINQ is implemented over extension methods , these are only available when you explicitly do so. That is, LINQ methods will only be considered part of their object if they were made available with using
, otherwise they do not appear in Intellisense since they are not part of the object, they are auxiliary definitions apart and optional. >