Is there more to the C# “as” keyword than simple casting?

后端 未结 6 1986
囚心锁ツ
囚心锁ツ 2021-02-05 22:26

I\'m working through Josh Smith\'s CommandSink code obviously do not understand something about the \"as\" keyword in C#.

I don\'t understand why he wrote the line:

6条回答
  •  夕颜
    夕颜 (楼主)
    2021-02-05 23:03

    IsValid = _fe != null || _fce != null;
    

    and

    IsValid = depObj != null;
    

    are not the same tests because if depObj is not of type FrameworkElement nor FrameworkContentElement but is not null the second test will return true, while the first will return false.

提交回复
热议问题