Пример #1
0
        static void Test()
        {
            string?value = "not null";
            var    flag  = MyString.IsNullOrEmpty(value);
            string?input = "1.0.0.0";
            var    flag1 = MyVersion.TryParse(input, out Version? version);
            var    queue = new MyQueue <string>();

            queue.Enqueue(value);
            var flag2 = queue.TryDequeue(out value);

            flag2 = queue.TryDequeue(out value);
        }
Пример #2
0
        static void Test_MaybeNullWhen_NotNullWhen(string?s)
        {
            if (MyString.IsNullOrEmpty(s))
            {
                //这会生成一个警告
                //Console.WriteLine(s.Length);
                return;
            }
            Console.WriteLine(s.Length); //安全

            if (!MyVersion.TryParse(s, out var version))
            {
                //这里有一个警告
                //Console.WriteLine(version.Major);
                return;
            }
            Console.WriteLine(version.Major);
        }