Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/291.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# 如何修改LinkedList属性_C#_Linked List - Fatal编程技术网

C# 如何修改LinkedList属性

C# 如何修改LinkedList属性,c#,linked-list,C#,Linked List,我想在将项目添加到LinkedList之前修改其属性。我要添加的项有两个属性:ProductID和ProductValue,如下所示: public class Product { private byte _productID; public byte ProductID { get { return _productID; } set { _productID = value;

我想在将项目添加到LinkedList之前修改其属性。我要添加的项有两个属性:
ProductID
ProductValue
,如下所示:

public class Product
{

    private byte _productID;
    public byte ProductID
    {
        get { return _productID; }
        set
        {
            _productID = value;
            NotifyPropertyChanged("ProductID");
        }
    }

    private UInt16 _productValue;
    public UInt16 ProductValue
    {
        get { return _productValue; }
        set
        {
            _productValue = value;
            NotifyPropertyChanged("ProductValue");
        }
    }

}
Product previous = dll.ElementAt(i - 1);
if (previous.ProductID == 1)
现在我想根据LinkedList中先前的
ProductID
修改项目的
ProductValue
,例如,如果
previous.ProductID=1
,那么
next.ProductValue=previous.ProductValue+1
,但是我应该如何使用
LinkedList dll=new LinkedList()
来获取属性呢?提前谢谢

那么如何在LInkedList中获取ProductID呢

您可以使用ElemenAt方法获取列表中的元素,以访问
LinkedList
中的元素

使用此方法,可以使用for循环在集合中进行迭代。您可以得到如下元素:

public class Product
{

    private byte _productID;
    public byte ProductID
    {
        get { return _productID; }
        set
        {
            _productID = value;
            NotifyPropertyChanged("ProductID");
        }
    }

    private UInt16 _productValue;
    public UInt16 ProductValue
    {
        get { return _productValue; }
        set
        {
            _productValue = value;
            NotifyPropertyChanged("ProductValue");
        }
    }

}
Product previous = dll.ElementAt(i - 1);
if (previous.ProductID == 1)
并按如下方式访问该属性:

public class Product
{

    private byte _productID;
    public byte ProductID
    {
        get { return _productID; }
        set
        {
            _productID = value;
            NotifyPropertyChanged("ProductID");
        }
    }

    private UInt16 _productValue;
    public UInt16 ProductValue
    {
        get { return _productValue; }
        set
        {
            _productValue = value;
            NotifyPropertyChanged("ProductValue");
        }
    }

}
Product previous = dll.ElementAt(i - 1);
if (previous.ProductID == 1)
这将使您能够了解其余的内容。如果你还有困难,请给我留言

那么如何在LInkedList中获取ProductID呢

您可以使用ElemenAt方法获取列表中的元素,以访问
LinkedList
中的元素

使用此方法,可以使用for循环在集合中进行迭代。您可以得到如下元素:

public class Product
{

    private byte _productID;
    public byte ProductID
    {
        get { return _productID; }
        set
        {
            _productID = value;
            NotifyPropertyChanged("ProductID");
        }
    }

    private UInt16 _productValue;
    public UInt16 ProductValue
    {
        get { return _productValue; }
        set
        {
            _productValue = value;
            NotifyPropertyChanged("ProductValue");
        }
    }

}
Product previous = dll.ElementAt(i - 1);
if (previous.ProductID == 1)
并按如下方式访问该属性:

public class Product
{

    private byte _productID;
    public byte ProductID
    {
        get { return _productID; }
        set
        {
            _productID = value;
            NotifyPropertyChanged("ProductID");
        }
    }

    private UInt16 _productValue;
    public UInt16 ProductValue
    {
        get { return _productValue; }
        set
        {
            _productValue = value;
            NotifyPropertyChanged("ProductValue");
        }
    }

}
Product previous = dll.ElementAt(i - 1);
if (previous.ProductID == 1)

这将使您能够了解其余的内容。如果仍有困难,请给我留言

是否要在链接列表的每个项目中修改此选项?您将如何在具有上一个值的第一个项目中修改它?@MongZhu,除了第一个项目之外,因为它没有上一个节点。您是否尝试使用循环来执行此操作?那么在LinkedList中获取
ProductID
的方法是什么?是否要在链接列表的每个项目中修改此项?您将如何在第一个具有上一个值的项目中对其进行修改?@MongZhu,第一个项目除外,因为它没有上一个节点。您是否尝试使用循环进行修改?那么,在LinkedList中获取
ProductID
的方法是什么?