CSharp == 字符串比较

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
string a = null;
string b = null;
bool v = a == b;
AppLogger.Instance.Information($"null==null : {v}");
b = string.Empty;
v = a == b;
AppLogger.Instance.Information($"null==Empty : {v}");
a = string.Empty;
v = a == b;
AppLogger.Instance.Information($"Empty==Empty : {v}");
string a1 = new string(a);
v = a == b;
AppLogger.Instance.Information($"new string Empty==Empty : {v}");
string x = new string("123");
string y = new string("123");
v = x == y;
AppLogger.Instance.Information($"new string 123==new string 123 : {v}");
String x1 = new String("123");
String y1 = new String("123");
v = x1 == y1;
AppLogger.Instance.Information($"new String 123==new String 123 : {v}");

[2023-11-16 10:01:28.550 +08:00] [INF] MainWindow.xaml.cs TestEqu():46 null==null : True
[2023-11-16 10:01:28.593 +08:00] [INF] MainWindow.xaml.cs TestEqu():49 null==Empty : False
[2023-11-16 10:01:28.593 +08:00] [INF] MainWindow.xaml.cs TestEqu():52 Empty==Empty : True
[2023-11-16 10:01:28.593 +08:00] [INF] MainWindow.xaml.cs TestEqu():55 new string Empty==Empty : True
[2023-11-16 10:01:28.593 +08:00] [INF] MainWindow.xaml.cs TestEqu():59 new string 123==new string 123 : True
[2023-11-16 10:01:28.593 +08:00] [INF] MainWindow.xaml.cs TestEqu():63 new String 123==new String 123 : True