Formatting MAC address in C#

后端 未结 5 1224
灰色年华
灰色年华 2020-12-06 10:35

In my C# application, I want to get my MAC address by using NetworkInterface class as the following:

NetworkInterface nic in NetworkInterface.Ge         


        
5条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-06 11:06

    Try Something like this:

    // Insert Colons on MAC
    string MACwithColons = "";
    for (int i = 0; i < MAC.Length; i++) {
      MACwithColons = MACwithColons + MAC.Substring(i, 2) + ":";
      i++;
    }
    MACwithColons = MACwithColons.Substring(0, MACwithColons.Length - 1); // Remove the last colon
    

提交回复
热议问题