菜鸟问题,C# string关键字和String关键字是不是完全的等价的?还是有什么区别?

贝笨33 2004-11-26 09:35:12
RT
...全文
341 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
dazhu2 2004-11-26
  • 打赏
  • 举报
回复
同意楼上
gsky 2004-11-26
  • 打赏
  • 举报
回复
●string 类型表示一个 Unicode 字符的字符串。string 是 .NET 框架中 System.String 的别名。

尽管 string 是引用类型,但相等运算符(== 和 !=)被定义为比较 string 对象(而不是引用)的“值”(7.9.7 字符串相等运算符)。这使得对字符串相等性的测试更为直观。

string a = "hello";
string b = "h";
b += "ello"; // append to b
Console.WriteLine( a == b ); // output: True -- same value
Console.WriteLine( (object)a == b ); // False -- different objects
+ 运算符用于连接字符串:

string a = "good " + "morning";
[] 运算符访问 string 中的个别字符:

char x = "test"[2]; // x = 's';
字符串为 string 类型并可写成两种形式,即用引号引起来和用 @ 引起来。用引号引起来的字符串括在双引号 (") 内:

"good morning" // a string literal
并且可以包含包括换码序列在内的任何字符:

string a = "\\\u0066\n"; // backslash, letter f, new line
注意 转义码 \udddd(其中 dddd 是一个四位数)表示 Unicode 字符 U+dddd。还可识别 8 位 Unicode 转义码:\udddd\udddd。
用 @ 引起来的字符串以 @ 开头,并用双引号引起来。例如:

@"good morning" // a string literal
用 @ 引起来的优点在于换码序列“不”被处理,这样就可以轻松写出字符串,例如一个完全限定的文件名:

@"c:\Docs\Source\a.txt" // rather than "c:\\Docs\\Source\\a.txt"
若要在一个用 @ 引起来的字符串中包括一个双引号,请使用两对双引号:

@"""Ahoy!"" cried the captain." // "Ahoy!" cried the captain.
@ 符号的另一种用法是使用碰巧成为 C# 关键字的被引用的 (/reference) 标识符。有关更多信息,请参阅 2.4.2 标识符。

示例
// keyword_string.cs
using System;
class test
{
public static void Main( String[] args )
{
string a = "\u0068ello ";
string b = "world";
Console.WriteLine( a + b );
Console.WriteLine( a + b == "hello world" );
}
}
输出
hello world
True

英文帮助 具体区别可以感觉一下.
●String
The String structure depicts the organization of data in a file-version resource. It contains a string that describes a specific aspect of a file, for example, a file's version, its copyright notices, or its trademarks.

This structure is not a true C-language structure because it contains variable-length members. This structure was created solely to depict the organization of data in a version resource and does not appear in any of the header files shipped with the Microsoft® Platform Software Development Kit (SDK).

struct String {
WORD wLength;
WORD wValueLength;
WORD wType;
WCHAR szKey[];
WORD Padding[];
WORD Value[];
};
Members
wLength
Specifies the length, in bytes, of this String structure.
wValueLength
Specifies the size, in words, of the Value member.
wType
Specifies the type of data in the version resource. This member is 1 if the version resource contains text data and 0 if the version resource contains binary data.
szKey
Specifies an arbitrary Unicode string. The szKey member can be one or more of the following values. These values are guidelines only. String Meaning
Comments The Value member contains any additional information that should be displayed for diagnostic purposes. This string can be an arbitrary length.
CompanyName The Value member identifies the company that produced the file. For example, "Microsoft Corporation" or "Standard Microsystems Corporation, Inc."
FileDescription The Value member describes the file in such a way that it can be presented to users. This string may be presented in a list box when the user is choosing files to install. For example, "Keyboard driver for AT-style keyboards" or "Microsoft Word for Windows".
FileVersion The Value member identifies the version of this file. For example, Value could be "3.00A" or "5.00.RC2".
InternalName The Value member identifies the file's internal name, if one exists. For example, this string could contain the module name for a dynamic-link library (DLL), a virtual device name for a Windows virtual device, or a device name for an MS-DOS device driver.
LegalCopyright The Value member describes all copyright notices, trademarks, and registered trademarks that apply to the file. This should include the full text of all notices, legal symbols, copyright dates, trademark numbers, and so on. In English, this string should be in the format "Copyright Microsoft Corp. 1990–1994".
LegalTrademarks The Value member describes all trademarks and registered trademarks that apply to the file. This should include the full text of all notices, legal symbols, trademark numbers, and so on. In English, this string should be in the format "Windows is a trademark of Microsoft Corporation".
OriginalFilename The Value member identifies the original name of the file, not including a path. This enables an application to determine whether a file has been renamed by a user. This name may not be MS-DOS 8.3-format if the file is specific to a non-FAT file system.
PrivateBuild The Value member describes by whom, where, and why this private version of the file was built. This string should only be present if the VS_FF_PRIVATEBUILD flag is set in the dwFileFlags member of the VS_FIXEDFILEINFO structure. For example, Value could be "Built by OSCAR on \OSCAR2".
ProductName The Value member identifies the name of the product with which this file is distributed. For example, this string could be "Microsoft Windows".
ProductVersion The Value member identifies the version of the product with which this file is distributed. For example, Value could be "3.00A" or "5.00.RC2".
SpecialBuild The Value member describes how this version of the file differs from the normal version. This entry should only be present if the VS_FF_SPECIALBUILD flag is set in the dwFileFlags member of the VS_FIXEDFILEINFO structure. For example, Value could be "Private build for Olivetti solving mouse problems on M250 and M250E computers".


Padding
Contains as many zero words as necessary to align the Value member on a 32-bit boundary.
Value
Specifies a zero-terminated string. See the szKey member description for more information.
Remarks
A String structure may have an szKey value of, for example, "CompanyName" and a Value of "Microsoft Corporation". Another String structure with the same szKey value could contain a Value of "Microsoft GmbH". This might occur if the second String structure were associated with a StringTable structure whose szKey value is 040704b0 — that is, German/Unicode.

greennetboy 2004-11-26
  • 打赏
  • 举报
回复
string 类型表示一个 Unicode 字符的字符串。string 是 .NET Framework 中 System.String 的别名。请参考:ms-help://MS.MSDNQTR.2003FEB.2052/csref/html/vclrfString.htm
哈哈007哈 2004-11-26
  • 打赏
  • 举报
回复
yes
哈哈007哈 2004-11-26
  • 打赏
  • 举报
回复
yes
tongyuja 2004-11-26
  • 打赏
  • 举报
回复
String是.net的东西。
string是C#中,对String起的一个别名。
gabriel1 2004-11-26
  • 打赏
  • 举报
回复
string就是System.String的别名.
完全一样.
spacecm 2004-11-26
  • 打赏
  • 举报
回复
小写的string关键字好像就是System.String别称,完全一致,
同样的int,double等也是一样
brightheroes 2004-11-26
  • 打赏
  • 举报
回复
据一本比较权威的书上写的:完全等价

110,533

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧