Casting Y or N to bool C#

前端 未结 10 2202
故里飘歌
故里飘歌 2021-02-07 05:46

Just for neatness sake I was wondering, whether it\'s possible to cast Y or N to a bool? Something like this;

bool theanswer = Convert.ToBoolean(input);
         


        
10条回答
  •  失恋的感觉
    2021-02-07 06:07

    Or this?

    bool CastToBoolean(string input)
    {
        return input.Equals("Y", StringComparison.OrdinalIgnoreCase);
    }
    

提交回复
热议问题