开发者

How can I convert select list items to lowercase in C#?

开发者 https://www.devze.com 2022-12-10 01:16 出处:网络
I need to convert a select list (which is populated by a data feed) into lower case, I have traced as far some code in the relevant controller;

I need to convert a select list (which is populated by a data feed) into lower case, I have traced as far some code in the relevant controller;

private SelectList getAddres开发者_开发问答sCountriesListDD()
{
    var addressCountries = myOPG.AddressCountries;
    return new SelectList(addressCountries, "key", "value", "GBR");
}

The myopg part is the datafeed, I need to get the selectlist into lowercase.

How can I accomplish this?


Replace

var addressCountries = myOPG.AddressCountries;

with

var addressCountries = myOPG.AddressCountries
                            .Select(c => c.ToString().ToLowerInvariant());


if addressCountries is a list of strings, then something like this (using LINQ).....

var lcase = from c in addressCountries
select c.ToLower();
0

精彩评论

暂无评论...
验证码 换一张
取 消