Programming Language: C# (CSharp)

Namespace/Package Name: System

Class/Type: Vector3

Method/Function: Length

Examples at hotexamples.com: 30

The System.Vector3.Length method calculates the length or magnitude of a 3D vector. It is part of the System.Numerics.Vectors package library in C#.

**Example 1:** Finding the length of a vector

**Example 2:** Normalizing a vector with length 1

using System; using System.Numerics; class Program { static void Main() { Vector3 vector = new Vector3(3, 4, 5); float length = vector.Length(); // length = 7.071068f Console.WriteLine("The length of the vector is: " + length); } }

using System; using System.Numerics; class Program { static void Main() { Vector3 vector = new Vector3(2, 2, 0); Vector3 normalized = Vector3.Normalize(vector); Console.WriteLine("The normalized vector is: " + normalized); float length = normalized.Length(); // length = 1.0f Console.WriteLine("The length of the normalized vector is: " + length); } }In this example, we first create a vector with components (2, 2, 0). We then call the Vector3.Normalize method to create a new vector with the same direction but a length of 1. Finally, we use the Length method to confirm that the length of the normalized vector is indeed 1.0.

Frequently Used Methods

Frequently Used Methods

Frequently Used Methods

Related in langs

Frequently Used Methods

Related