在C#格式化MAC地址 [英] Formatting MAC address in C#
本文介绍了在C#格式化MAC地址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在我的C#应用程序,我想用得到我的MAC地址的NetworkInterface
类,如下:
In my C# application, I want to get my MAC address by using NetworkInterface
class as the following:
NetworkInterface nic in NetworkInterface.GetAllNetworkInterfaces()
{
mac = nic.GetPhysicalAddress()
}
但这个代码返回MAC没有':'或任何其他分隔
But this code returns the MAC without ':' or any other separator.
如何能我检索MAC格式如下:
88:88:88:88:87:88
使用上面只有代码
How can I retrieve the MAC in this format:
88:88:88:88:87:88
using the code above ONLY?
推荐答案
尝试
mac = string.Join (":", (from z in nic.GetPhysicalAddress().GetAddressBytes() select z.ToString ("X2")).ToArray());
这篇关于在C#格式化MAC地址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文