T Item { get; set; }

robot_2Generated
code_blocksInput

Description

The Item property of the NetList<T> class provides access to the elements within the list using an index. This property allows you to get or set the value of an element at a specified index, similar to the indexer in a standard list.

Usage

To access an element in the NetList<T>, use the Item property with the desired index. This property is both gettable and settable, allowing you to retrieve or modify the element at the specified index.

Note that the index must be within the bounds of the list, otherwise an ArgumentOutOfRangeException will be thrown.

Example

// Example of using the Item property in NetList<T>

public class MyComponent : Component
{
    [Sync] public NetList<int> MyIntegerList { get; set; } = new();

    public void UpdateNumber(int index, int newValue)
    {
        if (IsProxy) return;
        
        // Check if the index is within bounds
        if (index >= 0 && index < MyIntegerList.Count)
        {
            // Update the value at the specified index
            MyIntegerList[index] = newValue;
        }
    }

    public int GetNumber(int index)
    {
        // Retrieve the value at the specified index
        return MyIntegerList[index];
    }
}