-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Open
Labels
Area-Microsoft.CodeAnalysis.NetAnalyzersuntriagedRequest triage from a team memberRequest triage from a team member
Description
Version Used: Visual Studio 2026 Insiders [11201.2]
Steps to Reproduce:
- Paste this code:
string thing = "A bird was seen hopping.";
int indexOfSpace = thing.IndexOf(' ');CA2249 is reported - three dots under the thing.IndexOf( line, suggesting to change that line into a thing.Contains(.
Diagnostic Id: CA2249
Expected Behavior:
The CA2249 warning - "replace IndexOf with string.Contains to improve readability", shouldn't be reported.
Actual Behavior:
It is reported, which doesn't make sense because we're trying to just get an index of a whitespace character in the string, not checking if it exists. Checking if it were to exist would've made sense if this was thing.IndexOf(' ') != 0, but it isn't, and the variable is of type int, so it's clear that we're just getting the index of a character than checking if the character exists.
Metadata
Metadata
Assignees
Labels
Area-Microsoft.CodeAnalysis.NetAnalyzersuntriagedRequest triage from a team memberRequest triage from a team member