Reputation: 697
I have five different for web service
List<_FiltA> A= new List<_FiltA>();
List<_FiltB> B= new List<_FiltA>();
List<_FiltC> C= new List<_FiltA>();
List<_FiltD> D= new List<_FiltA>();
List<_MainFilt> Main= new List<_MainFilt>();
and 4 different method and 1 [WebMethod]
for each list's parameters
For ex:
[WebMethod]
public List<_MainFilt> Search(string p1,int p2 ...)
{
Some code here...
_FiltA= _FiltA(someParameters); //go to FiltA method
_FiltB= _FiltB(someParameters);
.
.
some code...
.
.
return Search; //get Seach values
}
public List<_FiltA> FiltA (someParameters)
{
_FiltA FLG3 = new _FiltA();
some codes....
FLG3 = new _FiltA
{
PriceLink = Link,
Price = valueSomething,
Price2 = valueSomething1
};
Search.Add(FLG3);
return FiltA ;
}
And 3 more method like this.
I want to combined these 4 list (_ListA,_ListB,_ListC,_ListD) in List<_MainFilt>
How can I combined? Or any suggestion for solving this problem?
Upvotes: 0
Views: 242
Reputation: 22955
You can just concatenate them.
public List<_MainFilt> Search(string p1,int p2 ...) {
var result = _FiltA(someParameters)
.Concat(_FiltB(someParameters))
.Concat(_FiltC(someParameters))
.Concat(_FiltD(someParameters))
.ToList();
// Do something with the list...
}
Upvotes: 1
Reputation: 96596
Instead of returning List<_MainFilt>
, you could return an object containing the 4 lists of filters, e.g:
public class Filters
{
public List<_FiltA> FilterA {get; set;}
public List<_FiltB> FilterB {get; set;}
public List<_FiltC> FilterC {get; set;}
public List<_FiltD> FilterD {get; set;}
}
...
[WebMethod]
public Filters Search(string p1,int p2 ...)
{
return new Filters {
FilterA = _FiltA(someParameters),
FilterB = _FiltB(someParameters),
FilterC = _FiltC(someParameters),
FilterD = _FiltD(someParameters),
};
}
Upvotes: 1