Click here to Skip to main content
15,893,622 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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; }
}
Posted
Updated 26-Aug-11 2:57am
v3
Comments
BillWoodruff 26-Aug-11 8:51am    
And your question is ?
#realJSOP 26-Aug-11 8:57am    
A homework question

1 solution

 
Share this answer
 
Comments
amitthakkar1987 26-Aug-11 9:22am    
Its not a homework...pls help how to create using LINQ

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900