Created
December 1, 2010 02:25
-
-
Save noqisofon/722824 to your computer and use it in GitHub Desktop.
Linq で IPv4 形式の IP アドレスオブジェクトを抽出する感じ。
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Net; | |
using System.Net.Sockets; | |
using System.Linq; | |
using System.Text; | |
namespace demo.linq.ipaddr { | |
/// <summary> | |
/// | |
/// </summary> | |
class LinqExtractsIPAddressSample { | |
/// <summary> | |
/// | |
/// </summary> | |
/// <param name="args"></param> | |
static void Main(string[] args) { | |
IPHostEntry host = Dns.GetHostEntry( Dns.GetHostName() ); | |
// Linq で IPv4 形式の IP アドレスオブジェクトを抽出します。 | |
IEnumerable<IPAddress> ret = from address in host.AddressList | |
where | |
address.AddressFamily == AddressFamily.InterNetwork | |
select address; | |
// 列挙子を取得し、 | |
var e = ret.GetEnumerator(); | |
// カーソルを次(0)に合わせ、 | |
if ( e.MoveNext() ) | |
// 現在、カーソルが指している要素を表示します。 | |
Console.WriteLine( e.Current ); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment