Cast curiosity



Hello
The following code snippet works fine...
....
string str = "";
ArrayList ac = new ArrayList();
char c = 'C';
ac.Add(c);

str += ac[0];
.....

However, if instead of str += ac[0] I use

str = ac[0];

the compiler complains...
"cannot implicitly convert type 'object' to 'string'
and I have to cast it to string, eg
str = (string)ac[0]

Its not a problem..just trying to understand...


.



Relevant Pages

  • Re: return a string
    ... Here, you're saying to return a character, not a string. ... char * prt_tralha ... since you've allocated new memory for tralha. ... the third compiler error. ...
    (comp.lang.c)
  • Re: type of "string"
    ... Well, the above writing doesn't have anything named "String", so I can't ... The function foo is declared as taking pointer to char. ... That is why compiler gives you a warning. ...
    (comp.lang.c.moderated)
  • Re: Thou shalt have no other gods before the ANSI C standard
    ... Then "string" may collide with the name of a standard function, ... architecture where "char" is signed (which is the case on most PC ... that the values taken by hash_value are positive, but the compiler is ...
    (sci.crypt)
  • Re: Dealing with ad hominem attacks in comp.programming
    ... look through each byte in the string until a null is found I know of no ... operations are perfectly possible these are not implementations of strlen. ... there is no char* object with which you could associate the length. ... the compiler could conceivably generate code to track the length ...
    (comp.programming)
  • VS2005 doesnt like its own suggestions
    ... A pull down list box poped up with a list of all selections available as ... The compiler then complains that "string is not a member of std"... ...
    (microsoft.public.vc.language)

Loading