C++ C# 中的 CString 等效项
MFC 的 CString
的 C#
等效项是什么?
What is the C#
equivalent for MFC's CString
?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
MFC 的 CString
的 C#
等效项是什么?
What is the C#
equivalent for MFC's CString
?
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
接受
或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
发布评论
评论(3)
可能是
System.String
。但为了提供更多有用的信息:System.String
实例是不可变的。连接/子字符串/等实际上创建了新的字符串对象,因此使用字符串实例作为构建输出的缓冲区是一个非常糟糕的主意,如果您打算这样做的话。将System.String
视为const CString
。System.Text.StringBuilder
用于构建和操作字符串内容。它有一个.ToString()
方法,您可以调用它来将其内容转换为正确的字符串。StringBuilder
会为您完成此操作。)正如 Billy 在该问题的另一个答案中提到的,C# 有一个关键字
string
,它本质上是System.String 的快捷方式。字符串
类型。两者完全等效,但如果您使用大写形式,大多数程序员都会对您提出警告。Probably
System.String
. But in an effort to provide more useful information:System.String
instances 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.String
as aconst CString
.System.Text.StringBuilder
is 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. (StringBuilder
does that for you.)As Billy mentioned in the other answer to this question, C# has a keyword
string
that is essentially a shortcut to theSystem.String
type. Both are completely equivalent, though most coders will LART you if you use the uppercase form.您可以尝试使用String,看看是否有帮助。
You can try to use String, and see if it helps.
您知道,
CString
并不是正确完成 OO 设计的光辉示例。 MS 不断地为其添加会员功能,直到它像一把瑞士军刀……但仍然缺少重要的功能。使用 CString 可以做的任何事情都可以通过不可变的“System.String”和许多支持类来更好地完成。
You know,
CString
ain't exactly a shining example of OO design done right. MS kept adding member functions to it until it resembled a Swiss army knife... while still missing impotant functions.Anything you can do with a CString can be better done with the immutable 'System.String` and a number of support classes.