我有五种不同的网络服务
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>();
每个列表的参数有<4>和4个不同的方法和1 [WebMethod]
例如:
[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 ;
}
还有3个像这样的方法。
我想在List<_MainFilt>
中合并这4个列表(_ListA,_ListB,_ListC,_ListD)如何组合?或者解决这个问题的任何建议?
答案 0 :(得分:1)
您可以返回包含4个过滤器列表的对象,而不是返回List<_MainFilt>
,例如:
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),
};
}
答案 1 :(得分:1)
你可以concatenate他们。
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...
}