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