您好,欢迎访问一九零五行业门户网

C# 中的字符串文字与字符串对象

字符串文字字符串文字或常量用双引号“”或@“”括起来。字符串包含与字符文字类似的字符:纯字符、转义序列和通用字符。
以下是字符串文字的一些示例 -
hello, world""welcome, \
以下是显示字符串文字用法的示例 -
示例using system;namespace demo { class program { static void main(string[] args) { // string string str1 ="hello, world"; console.writeline(str1); // multi-line string string str2 = @"welcome, hope you are doing great!"; console.writeline(str2); } }}
字符串对象使用以下方法之一创建字符串对象 -
通过将字符串文字分配给字符串变量 通过使用 string 类构造函数通过使用字符串连接运算符 (+)通过检索属性或调用返回字符串的方法通过调用格式化方法将值或对象转换为其字符串表示形式以下是如何创建字符串对象并比较两个字符串 -
示例using system;namespace demo { class program { static void main(string[] args) { string str1 = "john"; string str2 = "andy"; if (string.compare(str1, str2) == 0) { console.writeline(str1 + " and " + str2 + " are equal strings."); } else { console.writeline(str1 + " and " + str2 + " are not equal strings."); } console.readkey() ; } }}
以上就是c# 中的字符串文字与字符串对象的详细内容。
其它类似信息

推荐信息