Array.ToString() returning System.Char[] c#
Array.ToString() returning System.Char[] c#
Calling ToString
on a simple array only returns T[]
regardless what the type T
is. It doesnt have any special handling for char[]
.
To convert a char[]
to string
you can use:
string s = new string(charArray);
But for your concrete problem there is an even simpler solution:
string stars = new string(*, PlayerOneWord.Length);
The constructor public String(char c, int count)
repeats c
count
times.
The variable stars
is an array of chars. This is the reason you get this error. As it is stated in MSDN
Returns a string that represents the current object.
In order you get a string from the characters in this array, you could use this:
Console.Write(Word to Guess: {0} , new String(stars));
Array.ToString() returning System.Char[] c#
The correct way to do this would be:
string StarString = new string(stars);
ToString() calls the standard implementation of the Array-classs ToString-method which is the same for all Arrays and similarily to object only returns the fully qualified class name.
Related posts
- matplotlib basemap – Python,IndexError: arrays used as indices must be of integer (or boolean) type
- How to initialize a two-dimensional array in Python?
- How to declare an array in Python?
- How to read a text file into a list or an array with Python
- How to parse JSON Array of objects in python
- arrays – Root mean square of a function in python
- python: how to identify if a variable is an array or a scalar
- Can I put a tuple into an array in python?