c# - Make a string out of a single tab character -
i want create string consists of single character such '\t' , that's it, string class constructor won't accept it.
string mytab = new string( '\t' );
this gave me:
error 2 argument 1: cannot convert 'char' 'char*'
okay, thought wouldn't need pointers after switching c++, i'll give 1 then:
char onechar = '\t'; string mytab = new string( &onechar );
gives:
error 1 pointers , fixed size buffers may used in unsafe context
so tried clumsy conversion instead without success:
string mytab = new string( tostring('\t') );
the error here is:
error 3 argument 1: cannot convert 'string' 'char[]'
this simplest issue ever , irritates me lot. can tell me how solve , why string class isn't made accept single characters?
char
, string
different data types. can't use char
string
expected (or matter, char*
or char[]
expected).
the constructor takes char*
can used in unsafe
context (see other answers), unless you've got real reason going unsafe
, don't (however tempting c++ background).
'\t'
defines char
"\t"
defines 1 character string
as such wouldn't
string mystring = "\t";
be fine?
if want convert char
string
string mystring = mychar.tostring();
Comments
Post a Comment