473,396 Members | 2,059 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

char to string fails

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
Nov 6 '07 #1
3 4990
double quotes indicate string type, single quotes indicate char type
so try:

ch[0] = '-';

dave wrote:
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

Nov 6 '07 #2
David,

It's this line:

ch[0]="-";

It should be:

ch[0]='-';

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

--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"dave" <sp*****@nospammer.netwrote in message
news:e6*******************@bignews4.bellsouth.net. ..
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


Nov 6 '07 #3
As the exception message indicates, there is no implicit cast from string to
char.
Use this instead (with single quote marks):
ch[0]='-';
-- Peter
http://www.eggheadcafe.com
unBlog: http://petesbloggerama.blogspot.com
BlogMetaFinder: http://www.blogmetafinder.com

"dave" wrote:
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
Nov 6 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Andreas Müller | last post by:
hi @all, I have a char* string array and i want to fill it up in a while loop: while(i<3){ length = read(STDIN_FILENO, inputBuffer, sizeof(inputBuffer); ... } after this the array should...
4
by: Pokerkook | last post by:
Hello, If anybody could help me with this I would greatly appreciate it. Or at least tell me why I get the output of this garbage: 49 49 10 49 52
7
by: techno | last post by:
Dear all, Our bitmap has some x00 values ( '\0' ) and i am storing it in char* array. the problem is that the '\0' is treated as eos character in c and it is truncating it so the characters...
33
by: Jordan Tiona | last post by:
How can I make one of these? I'm trying to get my program to store a string into a variable, but it only stores one line. -- "No eye has seen, no ear has heard, no mind can conceive what God...
14
by: gustavo | last post by:
I was looking at the Sendmail's source code, and i've got confused about this kind of initialization: ------------------------ struct prival PrivacyValues = { { "public", PRIV_PUBLIC }, {...
33
by: Michael B Allen | last post by:
Hello, Early on I decided that all text (what most people call "strings" ) in my code would be unsigned char *. The reasoning is that the elements of these arrays are decidedly not signed. In...
13
by: Hongyu | last post by:
Hi, I have a datetime char string returned from ctime_r, and it is in the format like ""Wed Jun 30 21:49:08 1993\n\0", which has 26 chars including the last terminate char '\0', and i would...
2
by: Austin326 | last post by:
Hi Everyone, I have a problem that is quite frusturating. I am passing in an image from a database, which is to be accessed in an image button. When I dynamically add the string for an sql...
1
by: eldadno1 | last post by:
I'm actually a Java programmer, and I'm messing with JNI a bit, so I've managed to pass an int from java to c++ and to c# and back. no problems cause it gets serialized automatically. but when...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.