Trying to understand ?. (null-conditional) operator in C#

前端 未结 1 989
小鲜肉
小鲜肉 2021-02-11 12:03

I have this very simple example:

class Program
{
    class A
    {
        public bool B;
    }

    static void Main()
    {
        System.Collections.ArrayLis         


        
相关标签:
1条回答
  • 2021-02-11 12:50
    • list?.Count > 0: Here you compare an int? to an int, yielding a bool, since lifted comparison operators return a bool, not a bool?.
    • a?.B: Here, you have a bool?. if, however, requires a bool.
    0 讨论(0)
提交回复
热议问题