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

前端 未结 1 659
醉梦人生
醉梦人生 2021-02-11 11:51

I have this very simple example:

class Program
{
    class A
    {
        public bool B;
    }

    static void Main()
    {
        System.Collections.ArrayLis         


        
相关标签:
1条回答
  • 2021-02-11 12:33
    • 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)
提交回复
热议问题