How to manufacture an empty string in .NET?

后端 未结 3 1633
[愿得一人]
[愿得一人] 2021-01-18 13:35

I have written a piece of optimized code that contains special cases for null and empty strings. I am now trying to write a unit test for this code. In order to

3条回答
  •  刺人心
    刺人心 (楼主)
    2021-01-18 14:04

    You can use the Obsolete method String.Copy

    string s1 = "";
    string s2 = String.Copy("");
    Assert.IsTrue(s1.Length == 0 && s2.Length == 0);
    Assert.IsTrue(!ReferenceEquals(s1, s2));
    

提交回复
热议问题