Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/326.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 使用Get集合的二进制转换器_C# - Fatal编程技术网

C# 使用Get集合的二进制转换器

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

我使用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 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;