gpt4 book ai didi

c# - IPAddress.[Try]Parse解析192.168为192.0.0.168

转载 作者:行者123 更新时间:2023-11-30 13:12:10 32 4
gpt4 key购买 nike

我有以下场景:

IPAddress ip;
IPAddress.TryParse("192.168", out ip);
if(ip == null){//do something with IP}

我预计解析会失败,但它被解析为“192.0.0.168”。我在这里错过了什么? (IPAddress.Parse 作用相同)

最佳答案

来自 Parse 的文档:

The number of parts (each part is separated by a period) in ipString determines how the IP address is constructed. A one part address is stored directly in the network address. A two part address, convenient for specifying a class A address, puts the leading part in the first byte and the trailing part in the right-most three bytes of the network address. A three part address, convenient for specifying a class B address, puts the first part in the first byte, the second part in the second byte, and the final part in the right-most two bytes of the network address. For example:

Number of parts and example ipString | IPv4 address for IPAddress
1 -- "65536" | 0.0.255.255
2 -- "20.2" | 20.0.0.2
2 -- "20.65535" | 20.0.255.255
3 -- "128.1.2" | 128.1.0.2

关于c# - IPAddress.[Try]Parse解析192.168为192.0.0.168,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12566664/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com