Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how can I convert a char to a char* in c#?

Tags:

c#

how can I convert a char to a char* in c#?

I'm initializeing a String object like this:

String test=new String('c');

and I'm getting this error:

Argument '1': cannot convert from 'char' to 'char*'

like image 789
Uince Avatar asked Jan 13 '10 13:01

Uince


1 Answers

That is a bit of a strange way to initialize a string, if you know beforehand what you want to store in it.

You can simply use:

String test="c";

If you have a specific need to convert a char variable to a string, you can use the built in ToString() function:

String test = myCharVariable.ToString();
like image 75
Oded Avatar answered Oct 07 '22 17:10

Oded