C# 使用Get集合的二进制转换器
我使用Get和Set方法在windows窗体中制作一个二进制转换器 执行转换的代码C# 使用Get集合的二进制转换器,c#,C#,我使用Get和Set方法在windows窗体中制作一个二进制转换器 执行转换的代码 class SubnetConvert { private int numconvert; private string OctetToBinary; public int OctetConvert { get { return numconvert; } set { List<int> Subnet = new List<int>(new in
class SubnetConvert
{
private int numconvert;
private string OctetToBinary;
public int OctetConvert
{
get
{
return numconvert;
}
set
{
List<int> Subnet = new List<int>(new int[] { 128, 64, 32, 16, 8, 4, 2, 1 });
foreach (int num in Subnet)
{
if (num <= numconvert)
{
numconvert -= num;
OctetToBinary += "1";
}
else
{
OctetToBinary += "0";
}
}
}
}
public string SendBinary
{
set
{
OctetToBinary = value;
}
get
{
return OctetToBinary;
}
}
此时,返回的唯一值是此行之前的8 0s或8 1s:
List<int> Subnet = new List<int>(new int[] { 128, 64, 32, 16, 8, 4, 2, 1 });
numconvert = value;
这是一个很好的例子,说明了如何不使用属性…而且您从未设置numConvert,因此它始终为0
numconvert = value;