是否有原生的.NET类型CIDR子网?子网、类型、NET、CIDR

2023-09-03 12:19:18 作者:青春喂了作业

这是很简单的,以code了一个类来存储/验证像 192.168.0.0/16 ,但我很好奇,如果本机类型为这个已经在.NET中存在?我会想象它会工作很像 ip地址

It's simple enough to code up a class to store/validate something like 192.168.0.0/16, but I was curious if a native type for this already existed in .NET? I would imagine it would work a lot like IPAddress:

CIDR subnet = CIDR.Parse("192.168.0.0/16");

基本上它只是需要确保你正在使用的IPv4或IPv6地址,然后将该位数您指定的有效期为这种类型。

Basically it just needs to make sure you're working with an IPv4 or IPv6 address and then that the number of bits your specifying is valid for that type.

推荐答案

没有出现这样的原生类型在.NET中,您将需要来发展你的自我。

No there is such native type in .NET, you will need to develop one your self.