Hi there,
I'm using SonarLint in Visual Studio 2017 with C# code. I have a piece of code that looks like the following:
public static void DoSomething(IList<int> numbers)
{
if (numbers.Count != 0)
{
var myNumber = numbers[0];
Console.WriteLine(myNumber);
}
}
SonarLint for Visual Studio 2017 reports that we should use a more generic type (like ICollection<int>) for numbers. This would be true if we wouldn't access it using a index.
When removing the if statement, like below, SonarLint does not complain anymore, so it seems like it does not see that we access the collection using the index when it's wrapped in an if statement.
public static void DoSomething(IList<int> numbers)
{
var myNumber = numbers[0];
Console.WriteLine(myNumber);
}
Am I missing something here, or did I discover a bug?
Regards,
Tonni Tielens