Description
This issue has been moved from a ticket on Developer Community.
[severity:It bothers me. A fix would be nice]
Dear ladies and gentlemen,
The Problem:
public static class InvalidChars
{
public const string InvalidNameChars = "";
public static string CleanName(this string input)
{
if (string. IsNullOrWhiteSpace(input))
{
return input;
}
var newInput = input;
foreach (var c in InvalidNameChars)
{
newInput = newInput.Remove(c);
}
return newInput;
}
}
I was writing the following piece of code.
I originally wanted to use replace with an empty character, however then I saw Remove in the autocomplete dropdown and decided to try it.
Thankfully I saw the declaration of the function before proceeding:
There is no override that takes a char.
For some reason it just automatically casts the char into an int without any warnings.
I tried it with a fresh .NET 8 project (We are using .NET 8) as well, no warnings.
My VS Version is 17.13.6
While I don't think it's such an important issue, it could be dangerous if someone were to just write code and trust the editor. (Which I think we are all guilty of nowadays)
Thank you for your time.
Sincerely,
Istvan Galfi
Original Comments
Feedback Bot on 4/13/2025, 10:13 PM:
We have directed your feedback to the appropriate engineering team for further evaluation. The team will review the feedback and notify you about the next steps.