C
C#2mo 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
Theos2mo ago
hmm, it acutally seems to return 2 elements correctly
No description
Theos
Theos2mo ago
but the foreach loop fails
Theos
Theos2mo ago
this is only called once
No description
Mayor McCheese
Mayor McCheese2mo ago
What does "fails" mean? Throws an exception?
Want results from more Discord servers?
Add your server
More Posts