0
I have a List
made with the following code:
List<frase> frases = new List<frase>();
According to the documentation of System.Collections.Generic
, my code is right. But for some reason C# is not finding the List
, what I’m doing wrong?
0
I have a List
made with the following code:
List<frase> frases = new List<frase>();
According to the documentation of System.Collections.Generic
, my code is right. But for some reason C# is not finding the List
, what I’m doing wrong?
2
You are trying to use the variable in the class scope, not within a method. So it won’t work.
public class User
{
List<Frase> frases = new List<Frase>(); // isso é um atributo, não uma variável local
// isso abaixo não irá funcionar, não é possível executar
// trechos de código neste estilo no escopo da classe
frases.Add(new Frase("Olá"));
public void Metodo()
{
frases.Add(new Frase("Olá")); // aqui o atributo está sendo usado corretamente, não terá problemas
}
}
Browser other questions tagged c# list collection
You are not signed in. Login or sign up in order to post.
You are trying to use the variable in the class scope, not within a method. So it won’t work.
– Gabriel Katakura
@Gabrielkatakura It worked, thanks. Wouldn’t it be better to write this in answer form? To make it more organized and also to make it easier for those who have the same problem in the future.
– Francisco
Okay, I made an answer indicating the solution.
– Gabriel Katakura