Casting Y or N to bool C#

前端 未结 10 2198
故里飘歌
故里飘歌 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:09

    I faced the same problem but solved other way.

    bool b=true; 
            decimal dec; 
            string CurLine = "";        
            CurLine = sr.ReadLine();
            string[] splitArray = CurLine.Split(new Char[] { '=' });
            splitArray[1] = splitArray[1].Trim();
            if (splitArray[1].Equals("Y") || splitArray[1].Equals("y")) b = true; else b = false;
            CurChADetails.DesignedProfileRawDataDsty1.Commen.IsPad = b;
    

提交回复
热议问题