?: ?? Operators Instead Of IF|ELSE

前端 未结 9 1646
粉色の甜心
粉色の甜心 2020-11-28 02:09
public string Source
{
    get
    {
        /*
        if ( Source == null ){
            return string . Empty;
        } else {
            return Source;
                


        
9条回答
  •  再見小時候
    2020-11-28 02:39

    The "do nothing" doesn't really work for ?

    if by // Return Nothing you actually mean return null then write

    return Source;
    

    if you mean, ignore the codepath then write

     if ( Source != null )
                {
                    return Source;
                }
    // source is null so continue on.
    

    And for the last

     if ( Source != value )
                { Source = value;
                    RaisePropertyChanged ( "Source" );
                }
    
    // nothing done.
    

提交回复
热议问题