以小写形式返回函数名称 [英] Return the name of a function in lowercase
本文介绍了以小写形式返回函数名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在我的项目(ASP.net MVC)中,我必须返回功能的名称(我读入的CSV文件) 小写.因为现在我已经将函数分组,并且它以相同的名称返回函数(有时以小写形式,有时以大写形式).我不知道如何解决这个问题?
In my project (ASP.net MVC) i have to return the name of a function (CSV File i read in) in lowercase. Because for now i have grouped the functions and it return functions with the same name (sometimes in lower case and sometimes in upper case). I don't know how to solve this problem?
//HomeController
public List<DescFunctionDataDTO> DescFunctionData()
{
Console.WriteLine("DescFunctionData");
var descItemsStamp = db.ChartDatas
.GroupBy(x => new { x.Function });
var descItems = descItemsStamp
.Select(x => new DescFunctionDataDTO
{
function = x.Select(b => b.Function).Distinct(),
functionavg = Math.Round(x.Average(y => y.Duration), 2),
})
.OrderByDescending(x => x.functionavg)
.ToList();
return descItems;
}
//DTO
public class DescFunctionDataDTO
{
public IEnumerable<string> function { get; set; }
public double functionavg { get; set; }
}
//JS-File
function showDescDuration() {
$.getJSON(`/Home/DescFunctionData`)
.then(data => {
console.log(data);
$('#rankingMax').find("tr:gt(0)").fadeOut().empty();
var i = 1;
for (let item of data) {
console.log('loop');
$('<tr>').appendTo('#rankingMax')
.append($('<td>').html("#"+i))
.append($('<td>').html(item.function))
.append($('<td>').html(item.functionavg + " ms"));
i++;
}
});
}
推荐答案
您可以使用预定义的函数string.ToLower()这样,
you can use pre-defined function string.ToLower() like this,
var descItemsStamp = db.ChartDatas
.GroupBy(x => new { x.Function });
var descItems = descItemsStamp
.Select(x => new DescFunctionDataDTO
{
function = x.Select(b => b.Function.ToLower()).Distinct(),
functionavg = Math.Round(x.Average(y => y.Duration), 2),
})
.OrderByDescending(x => x.functionavg)
.ToList();
return descItems;
这篇关于以小写形式返回函数名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文