Iミリメートルの2リストをマージ:C#が、このモデルを使用してIP
public class IPList
{
public List<string> websites { get; set; }
public int total_websites { get; set; }
public string ip { get; set; }
}
リストは次の値があります。
[{
"websites": ["test1.com", "test2.com", "test3.com", "test4.com"],
"total_websites": 4,
"ip": "104.130.124.96"
}, {
"websites": ["test5.com"],
"total_websites": 1,
"ip": "104.130.124.80"
}, {
"websites": ["test6.com"],
"total_websites": 1,
"ip": "104.130.124.70"
}]
は私が範囲内のすべてのIPを持つ新しいリストを持っていると思いますが104.130.124.x
(104.130.124.0 to 104.130.124.255
)。私がやった何
:
List<IPList> NewIPList = new List<IPList>();
for (int i = 0; i < 255; i++)
{
string TempIP = "104.130.124." + i;
IPListTake10 TempIpList = IPList.Where(p => p.ip == TempIP).FirstOrDefault();
if (TempIpList != null)
{
NewIPList.Add(new IPList{ ip = TempIP, total_websites = TempIpList.total_websites, websites = TempIpList.websites });
}
else
{
NewIPList.Add(new IPList{ ip = TempIP, total_websites = 0});
}
}
はそれを行うには良い方法はありますか?これらのいずれかの方法を使用して、たぶん
: http://alicebobandmallory.com/articles/2012/10/18/merge-collections-without-duplicates-in-c
- リストとLINQは
- 辞書のことができます
- HashSetのとされたIEqualityComparer
- LINQ連合(EU)とされたIEqualityComparer
なぜ、 '' 'NewIPList = IPList.Where(x => x.ip.StartsWith(" 104.130.124。 "))ですか?ToList()' ''? – tym32167
最初に見つけられることは、total_websitesの設定者を削除し、ゲッターでウェブサイトを使用することです。 –
'Ip'プロパティに' String'の代わりに 'IPAddress'を使わないのはなぜですか? –