# Vector Struct

## Definition

Represents a displacement in 2-D space.

``public value class Vector : IFormattable``
``````[System.ComponentModel.TypeConverter(typeof(System.Windows.VectorConverter))]
public struct Vector : IFormattable``````
``````[System.ComponentModel.TypeConverter(typeof(System.Windows.VectorConverter))]
[System.Serializable]
public struct Vector : IFormattable``````
``````type Vector = struct
interface IFormattable``````
``````Public Structure Vector
Implements IFormattable``````
Inheritance
Vector
Attributes
Implements
<xref href="System.IFormattable?alt=System.IFormattable&text=IFormattable" data-throw-if-not-resolved="True"/>

## Examples

The following example shows how to add two Vector structures.

``````// Adds a Vector to a Vector using the overloaded + operator.

Vector vector1 = new Vector(20, 30);
Vector vector2 = new Vector(45, 70);
Vector vectorResult = new Vector();

// vectorResult is equal to (65,100)
vectorResult = vector1 + vector2;
``````
``````' Adds a Vector to a Vector using the overloaded + operator.

Dim vector1 As New Vector(20, 30)
Dim vector2 As New Vector(45, 70)
Dim vectorResult As New Vector()

' vectorResult is equal to (65,100)
vectorResult = vector1 + vector2
``````

## Remarks

A Point represents a fixed position, but a Vector represents a direction and a magnitude (for example, velocity or acceleration). Thus, the endpoints of a line segment are points but their difference is a vector; that is, the direction and length of that line segment.

In XAML, the delimiter between the X and Y values of a Vector can be either a comma or a space.

Some cultures might use the comma character as the decimal delimiter instead of the period character. XAML processing for invariant culture defaults to en-US in most XAML processor implementations, and expects the period to be the decimal delimiter. You should avoid using the comma character as the decimal delimiter if specifying a Vector in XAML, because that will clash with the string type conversion of a Vector attribute value into the X and Y components.

### XAML Attribute Usage

``````<object property="x,y"/>
-or-
<object property="x y"/>
``````

x

y

## Constructors

 Initializes a new instance of the Vector structure.

## Properties

 Gets the length of this vector. Gets the square of the length of this vector. Gets or sets the X component of this vector. Gets or sets the Y component of this vector.

## Methods

 Translates the specified point by the specified vector and returns the resulting point. Adds two vectors and returns the result as a Vector structure. Retrieves the angle, expressed in degrees, between the two specified vectors. Calculates the cross product of two vectors. Calculates the determinant of two vectors. Divides the specified vector by the specified scalar and returns the result as a Vector. Determines whether the specified Object is a Vector structure and, if it is, whether it has the same X and Y values as this vector. Compares two vectors for equality. Compares the two specified vectors for equality. Returns the hash code for this vector. Multiplies the specified scalar by the specified vector and returns the resulting Vector. Multiplies the specified vector by the specified scalar and returns the resulting Vector. Transforms the coordinate space of the specified vector using the specified Matrix. Calculates the dot product of the two specified vectors and returns the result as a Double. Negates this vector. The vector has the same magnitude as before, but its direction is now opposite. Normalizes this vector. Converts a string representation of a vector into the equivalent Vector structure. Subtracts the specified vector from another specified vector. Returns the string representation of this Vector structure. Returns the string representation of this Vector structure with the specified formatting information.

## Operators

 Translates a point by the specified vector and returns the resulting point. Adds two vectors and returns the result as a vector. Divides the specified vector by the specified scalar and returns the resulting vector. Compares two vectors for equality. Creates a Point with the X and Y values of this vector. Creates a Size from the offsets of this vector. Compares two vectors for inequality. Multiplies the specified scalar by the specified vector and returns the resulting vector. Multiplies the specified vector by the specified scalar and returns the resulting vector. Transforms the coordinate space of the specified vector using the specified Matrix. Calculates the dot product of the two specified vector structures and returns the result as a Double. Subtracts one specified vector from another. Negates the specified vector.

## Explicit Interface Implementations

 This member supports the Windows Presentation Foundation (WPF) infrastructure and is not intended to be used directly from your code. For a description of this member, see ToString(String, IFormatProvider).