© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•2y ago•
4 replies
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
image.png
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

❔ ✅ Scrape all <table> </table> elements
C#CC# / help
3y ago
❔ LINQ: Group and extract all consecutive elements from List that match predicate
C#CC# / help
3y ago
✅ The code prints out no list elements
C#CC# / help
3y ago