This rule appears to have some logic issues. It flags positive in the below snippet. It seems like using the object initializer in the Add call causes it to malfunction.
var myList = new List<SomeObject>();
foreach(var other in Enumerable.Range(0,100))
{
myList.Add(new SomeObject { Value = other});
}
myList.Foreach(i => Console.WriteLine(i));
Thanks for this report. I’ll need a few more details to make sure you’re seeing this in the latest version. Can you provide your SonarLint flavor / IDE, and SonarLint version, please?