我有以下代码来复制列表X
时间的成员。
虽然它有效,但感觉不是特别干净。
实时代码示例:http ://rextester.com/UIVZVX7918
public static List<ServiceEndPoint> GetServiceEndPoints()
{
const string source = "http://webSiteA.asmx,http://webSiteB.asmx";
const int instances = 3;
var splitEndPoints = source.Split(new[] { "," }, StringSplitOptions.RemoveEmptyEntries)
.Select((s, i) => new ServiceEndPoint
{
Index = i,
Uri = s
})
.ToList();
// Duplicate the contents of splitEndPoints "instances" number of times
var serviceEndPoints = new List<ServiceEndPoint>();
foreach (var point in splitEndPoints)
{
for (var i = 0; i < instances; i++)
{
serviceEndPoints.Add(point);
}
}
return serviceEndPoints;
}
public class ServiceEndPoint
{
public int Index { get; set; }
public string Uri { get; set; }
}
有更好的方法吗?