文章目录
1. 介绍
1.1 基本介绍
类结构
String官方参考文档:String类
1.2 深层细节
2. 构造和属性
2.1 String 构造
相关构造方法
class Test {
static void Main(string[] args) {
string s = new string("hello, world.");
}
}
2.2 String 属性
class Test {
static void Main() {
string str = "hello, world";
Console.WriteLine(str.Length);
Console.WriteLine(str[1]);
}
}
/*
12
e
*/
3. 方法
3.1 字符串判定
总结
代码
class Test {
static void Main() {
string[] s = new string[] {
null,
String.Empty,
"",
" \t ",
"hello"
};
for(int i = 0; i < s.Length; i ++) {
Console.Write(String.IsNullOrEmpty(s[i]) + " "); // True True True False False
}
Console.WriteLine();
for(int i = 0; i < s.Length; i++) {
Console.Write(String.IsNullOrWhiteSpace(s[i]) + " "); // True True True True False
}
}
}