本文介绍了使用LINQ创建FilterItem类的方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用LINQ实现FilterItem类的创建方法.
Create方法接受一个十进制数字列表,这些列表汇总到范围和小数位数中.
有三个范围:正数,负数和零;正数为零.正范围包括所有正数,等等.
比例尺是10的倍数,例如17300属于10000或10 ^ 4比例尺,1250000属于1000000
或10 ^ 6、1350属于1000比例或10 ^ 3等
例如,对于此输入{17000,35000,120000,0,0,-15000,-1000000,-15000}
通过Web服务将FilterItem类序列化为XML时,输出看起来像这样:

Implement Create method of FilterItem class using LINQ.
Create method takes a list of decimal numbers that is aggregated into ranges and scales.
There are three ranges: positive, negative and zero; positive range includes all positive numbers, etc.
Scales are multiples of 10, for example, 17300 belong to 10000 or 10^4 scale, 1250000 belongs to 1000000
or 10^6, 1350 belong to 1000 scale or 10^3, etc
For example, for this input { 17000, 35000, 120000, 0, 0, -15000, -1000000, -15000 }
the output looks like this on the wire, when FilterItem class is serialized to XML by a web service:

<FilterItem Text="All Items" Value="" Count="8">
<SubFilterItems>
<FilterItem Text="Range" Value="(+) Positive" Count="3">
<SubFilterItems>
<FilterItem Text="Scale" Value="10,000" Count="2"/>
<FilterItem Text="Scale" Value="100,000" Count="2"/>
</SubFilterItems>
</FilterItem>
<FilterItem Text="Range" Value="(0) Zero" Count="2"/>
<FilterItem Text="Range" Value="(-) Negative" Count="3">
<SubFilterItems>
<FilterItem Text="Scale" Value="-10,000" Count="1"/>
<FilterItem Text="Scale" Value="-100,000" Count="1"/>
<FilterItem Text="Scale" Value="-1,000,000" Count="1"/>
</SubFilterItems>
</FilterItem>
</SubFilterItems>
</FilterItem>

/////////////////////////////////////////////////////////////////////////////////////
class Service
{
    public FilterItem Aggregate(decimal[] items)
    {
        return FilterItem.Create(items.ToList());
    }
}

/////////////////////////////////////////////////////////////////////////////////////
class FilterItem
{
    public static FilterItem Create(List<decimal> items)
    {
        //Write a LINQ statement here
        //Hint: var result = from item in items
        // group item by 1 into groupAll
        // select new FilterItem
        // {
        // Text = "All Items",
        // Count = groupAll.Count(),
        // SubFilterItems =
        // (from range in items
        // ...
        //return result.FirstOrDefault();
    }
    public string Text { get; set; }
    public string Value { get; set; }
    public int Count { get; set; }
    public List<FilterItem> SubFilterItems { get; set; }
}

推荐答案


这篇关于使用LINQ创建FilterItem类的方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-30 14:37