Edit

Share via


Vector.Addition Operator

Definition

Adds a vector to a point or to another vector.

Overloads

Addition(Vector, Vector)

Adds two vectors and returns the result as a vector.

Addition(Vector, Point)

Translates a point by the specified vector and returns the resulting point.

Addition(Vector, Vector)

Adds two vectors and returns the result as a vector.

C#
public static System.Windows.Vector operator +(System.Windows.Vector vector1, System.Windows.Vector vector2);

Parameters

vector1
Vector

The first vector to add.

vector2
Vector

The second vector to add.

Returns

The sum of vector1 and vector2.

Examples

The following example shows how to use this operator (+) to add two Vector structures and return a Vector.

C#
private Vector overloadedAdditionOperatorExample1()
{
    Vector vector1 = new Vector(20, 30);
    Vector vector2 = new Vector(45, 70);
    Vector vectorResult = new Vector();

    // Add the two vectors together.
    // vectorResult is equal to (65,100)
    vectorResult = vector1 + vector2;

    return vectorResult;
}

See also

Applies to

.NET Framework 4.8.1 and other versions
Product Versions
.NET Framework 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9, 10

Addition(Vector, Point)

Translates a point by the specified vector and returns the resulting point.

C#
public static System.Windows.Point operator +(System.Windows.Vector vector, System.Windows.Point point);

Parameters

vector
Vector

The vector used to translate point.

point
Point

The point to translate.

Returns

The result of translating point by vector.

Examples

The following example shows how to use this operator (+) to translate a Point structure to a Vector structure.

C#
private Point overloadedAdditionOperatorExample2()
{
    Point point1 = new Point(10, 5);
    Vector vector1 = new Vector(20, 30);
    Point pointResult = new Point();

    // Add the point to the vector.
    // pointResult is equal to (30,35).
    pointResult = point1 + vector1;

    return pointResult;
}

See also

Applies to

.NET Framework 4.8.1 and other versions
Product Versions
.NET Framework 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9, 10