字符串文字
字符串文字或常量用双引号“”或@“”括起来。字符串包含与字符文字类似的字符:纯字符、转义序列和通用字符。
以下是字符串文字的一些示例 -
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); } } }
字符串对象
使用以下方法之一创建字符串对象 -
以下是如何创建字符串对象并比较两个字符串 -
示例
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# 中的字符串文字与字符串对象的详细内容,更多请关注编程之家其它相关文章!
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。