How to make C# Switch Statement use IgnoreCase

后端 未结 10 1134
孤独总比滥情好
孤独总比滥情好 2020-11-27 16:56

If I have a switch-case statement where the object in the switch is string, is it possible to do an ignoreCase compare?

I have for instance:

string s =         


        
10条回答
  •  半阙折子戏
    2020-11-27 17:33

    I hope this helps try to convert the whole string into particular case either lower case or Upper case and use the Lowercase string for comparison:

    public string ConvertMeasurements(string unitType, string value)
    {
        switch (unitType.ToLower())
        {
            case "mmol/l": return (Double.Parse(value) * 0.0555).ToString();
            case "mg/dl": return (double.Parse(value) * 18.0182).ToString();
        }
    }
    

提交回复
热议问题