-4

//CS0266 Cannot implicitly convert type 'System.Collections.Generic.IEnumerable' to 'char[]'.

   foreach(string newstr in Reversewords)
    {
       var strArr = newstr.ToCharArray();
        char[] chaArr= strArr.Reverse(); // error in this line
        sb.Append(chaArr);
    }
A. B.
  • 1
  • 2
  • 5
    Does `char[] chaArr= strArr.Reverse().ToArray();` work? – Ibrennan208 Aug 27 '22 at 16:31
  • Does this answer your question: https://stackoverflow.com/questions/55824777/cannot-implicitly-convert-type-system-collections-generic-ienumerablestring-to? – Ibrennan208 Aug 27 '22 at 16:32
  • what is Reversewords. – Qwerty Aug 27 '22 at 16:32
  • @Qwerty Looks like it is a collection of strings that are being iterated over. – Ibrennan208 Aug 27 '22 at 16:33
  • 3
    Or instead of using the LINQ extension method use the static method of the array class `Array.Reverse` https://learn.microsoft.com/en-us/dotnet/api/system.array.reverse?view=net-6.0#system-array-reverse(system-array) – Rand Random Aug 27 '22 at 16:34
  • In NET 5/6/core you might directly use `sb.AppendJoin("", newstr.Reverse());` No need for the intermediate array buffer. https://learn.microsoft.com/en-us/dotnet/api/system.text.stringbuilder.appendjoin?view=net-6.0 – lidqy Aug 27 '22 at 16:47

2 Answers2

0

I think you shuold do this in other way, you can first, turn it to string.

Also you can find some intresting things about this here : IEnumerable<char> to string

0

You may use JoinAsString("")

Basma
  • 31
  • 1
  • 1
  • 8