What is the C# equivalent for MFC’s CString?
What is the C# equivalent for MFC’s CString ?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Probably
System.String. But in an effort to provide more useful information:System.Stringinstances are immutable. Concatenation/substring/etc actually create new string objects, so using a string instance as a buffer for building up output is a really bad idea, in case you were going to do that. Think ofSystem.Stringas aconst CString.System.Text.StringBuilderis used to build up and manipulate string content. It has a.ToString()method you can call to turn its contents into a proper string.char[]as a sort of string builder alternative, if you know exactly how long a generated string will turn out to be, but even so you can usenew StringBuilder(length)to specify a default initial capacity. You can then use the relevant append methods without having to keep around an index variable. (StringBuilderdoes that for you.)As Billy mentioned in the other answer to this question, C# has a keyword
stringthat is essentially a shortcut to theSystem.Stringtype. Both are completely equivalent, though most coders will LART you if you use the uppercase form.