float Item { get; set; }

book_4_sparkGenerated
code_blocksInput

Description

The Item property of the Vector3 struct allows you to access or modify the individual components of the vector using an index. This property is useful for iterating over the components of a vector or when you need to dynamically access a specific component by index.

Usage

Use the Item property to access the x, y, or z components of a Vector3 instance by index. The index values are as follows:

  • 0 for the x component
  • 1 for the y component
  • 2 for the z component

Attempting to access an index outside of this range will result in an IndexOutOfRangeException.

Example

Vector3 vector = new Vector3(1.0f, 2.0f, 3.0f);

// Accessing components using the Item property
float xComponent = vector[0]; // 1.0f
float yComponent = vector[1]; // 2.0f
float zComponent = vector[2]; // 3.0f

// Modifying components using the Item property
vector[0] = 4.0f; // x is now 4.0f
vector[1] = 5.0f; // y is now 5.0f
vector[2] = 6.0f; // z is now 6.0f