There is no such thing as a
StringBuilder
to
String
conversion.
StringBuilder
class provides you with a
toString
method which allows you to get the string which is actually stored in the internal buffer of the
StringBuilder
object.
You have to use
String s = sb.ToString();
,
sb
being a
variable of the
StringBuilder
class.
String s = (String)StringBuilder;
is not correct on at least two levels:
- You cannot cast a
StringBuilder
variable to a string directly.
StringBuilder
is a class, not a variable. You cannot cast a class to anything, you only cast variables.