C ++的CString相当于在C# [英] C++ CString equivalent in C#

查看:777
本文介绍了C ++的CString相当于在C#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

什么是 C#相当于MFC的的CString

What is the C# equivalent for MFC's CString?

推荐答案

也许 System.String 。但是,在努力提供更多有用信息:

Probably System.String. But in an effort to provide more useful information:


  • System.String 实例不可改变的。级联/子/等实际上是建立输出创建新的string对象,所以使用字符串实例作为缓冲区是一个非常糟糕的主意,如果你打算这样做。 System.String 看作一个常量CString

  • System.Text.StringBuilder 被用来建立和操作字符串内容。它有一个的ToString()方法,你可以打电话把其内容放到一个适当的字符串。

  • 您可以使用的char [] 作为一种字符串生成器替代的,如果你知道一个生成的字符串会究竟有多长练得,但即便如此,你可以使用新的StringBuilder (长)来指定一个默认的初始容量。然后,您可以使用相关的追加方法,而无需保持周围的指标变量。 (的StringBuilder 这是否给你的。)

  • 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 of System.String as a const 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.
  • You can use 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 use new 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.)

比利在对方提到回答这个问题,C#有一个关键字字符串这本质上是一个快捷方式到 System.String 键入。两者都是完全等效的,但如果你使用大写形式最程序员会LART你。

As Billy mentioned in the other answer to this question, C# has a keyword string that is essentially a shortcut to the System.String type. Both are completely equivalent, though most coders will LART you if you use the uppercase form.

这篇关于C ++的CString相当于在C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆