Vector2 v1 = new Vector2(-3.5f, 2.8f); Vector2 absV1 = Vector2.Abs(v1); Console.WriteLine(absV1); // Output: (3.5, 2.8)
Vector2 v2 = new Vector2(0.0f, -1.2f); Vector2 absV2 = Vector2.Abs(v2); Console.WriteLine(absV2); // Output: (0, 1.2)This example is similar to the previous one, but the initial Vector2 has a zero component. The Abs method still returns a Vector2 with positive or zero components, so the resulting Vector2 is (0, 1.2). Package library: The Vector2 Abs method is part of the System.Numerics.Vector2 class, which is included in the System.Numerics.dll assembly. This assembly is part of the .NET Framework and can be referenced in C# projects by adding a reference to the System.Numerics.dll file.