C
C#7mo ago
Theos

List not returning all matching elements

hey, I have this method
public List<T> GetStatementsOfType<T>() where T : ASTStatement
{
return statements.OfType<T>().ToList();
}
public List<T> GetStatementsOfType<T>() where T : ASTStatement
{
return statements.OfType<T>().ToList();
}
and i call it like this:
foreach(ASTVariableDeclaration dec in astScope.GetStatementsOfType<ASTVariableDeclaration>())
{
_globalVariables.Add(dec.name.value, null);
}
foreach(ASTVariableDeclaration dec in astScope.GetStatementsOfType<ASTVariableDeclaration>())
{
_globalVariables.Add(dec.name.value, null);
}
for some reason it only returns one element matching that type but it should return two
No description
4 Replies
Theos
Theos7mo ago
hmm, it acutally seems to return 2 elements correctly
No description
Theos
Theos7mo ago
but the foreach loop fails
Theos
Theos7mo ago
this is only called once
No description
Mayor McCheese
Mayor McCheese7mo ago
What does "fails" mean? Throws an exception?
Want results from more Discord servers?
Add your server