char to string fails

D

dave

char[] ch = new char[1];

ch[0]="-";

FileStream fp=new FileStream("z:\\" + "math" + ch[0].ToString() +
"optpivot",FileMode.Open,FileAccess.Read);



Why does this fail with Cannot implicitly convert type 'string' to 'char'
(CS0029) ?

Best

David
 
T

Trey Walpole

double quotes indicate string type, single quotes indicate char type
so try:

ch[0] = '-';
 
N

Nicholas Paldino [.NET/C# MVP]

David,

It's this line:

ch[0]="-";

It should be:

ch[0]='-';

Note the single quotes which are used to indicate a character literal.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

File handling 2
for loop 3
Split function 3
h0w readkey works? 6
Streaming Techniques 5
Convert a String to a char... 7
char[] to char 2
MD5CryptoServiceProvider - File Not Closing 8

Top