3

I try to Reverse my string but I get to following error

string str = word.Reverse();

error:

cannot convert from 'System.Collections.Generic.IEnumerable' to 'string'

anyone know what should I need to do ?

Hamid Pourjam
  • 20,441
  • 9
  • 58
  • 74
Yoav
  • 150
  • 3
  • 9

2 Answers2

11

You should build a new string.

string str = new string(word.Reverse().ToArray());

Calling ToArray() on an IEnumerable<T> will convert it to T[].

string has a constructor which get array of character and constructs a string.

Hamid Pourjam
  • 20,441
  • 9
  • 58
  • 74
3

You should join characters together to make new string.

string str = string.Join(string.Empty, word.Reverse());
Fred
  • 3,365
  • 4
  • 36
  • 57