ToCharArray()
when iterating a string CS-P1004The ToCharArray()
returns a char
array whose elements are the individual characters of the string
on which this method is called. However, this call is particularly redundant within a foreach
statement as foreach
allows you to iterate through the types that implement IEnumerable
or IEnumerable<T>
, such as string
in this case. Therefore, it is recommended that you get rid of this redundant call.
foreach (char ch in someString.ToCharArray())
{
// Some logic here
}
foreach (char ch in someString)
{
// Some logic here
}