Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7883473
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T04:32:29+00:00 2026-06-03T04:32:29+00:00

I wrote such a property (representing direction for my XNA game object): public Vector2

  • 0

I wrote such a property (representing direction for my XNA game object):

public Vector2 Direction
{
    get { return direction; }
    protected set
    {
        (direction = value).Normalize(); // ***
        angle = MathHelper.WrapAngle((float)Math.Atan(direction.X / direction.Y));
    }
}

set sets two equivalent fields which represent object’s orientation in angle and simultaneously in normalized vector.

Starting game failed because line marked by *** failed. It doesn’t normalize vector.
I changed this line to:

direction = value;
direction.Normalize();

and it works fine… Why?
I assumed that in line marked by *** first operation is assigning value and then normalising direction. But it’s not true.

___ ___ ____

Normalize() is method from Vector2 class.

//
// Summary:
//     Turns the current vector into a unit vector. The result is a vector one unit
//     in length pointing in the same direction as the original vector.
public void Normalize();
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T04:32:30+00:00Added an answer on June 3, 2026 at 4:32 am

    I am assuming Vector2 is a struct, or value type, which means it is passed-by-value and not by reference. When you assign value to direction, you are setting direction to a copy of value. Additionally, the object returned by the expression (direction = value) is a copy, and not the same instance that is in direction. You are calling Normalize on an object that is never stored outside of the setter block.

    For this same reason you cannot call methods or set properties on a struct returned from a property getter on a class. For instance, if the property from your example is in a class named Monkey, note:

    Monkey m = new Monkey();
    m.Direction = new Vector2(...);
    m.Direction.X = 2; // This will not compile.
    m.Direction.Normalize(); // This will not do what you expect.
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

When i wrote the following, i get such warning, and it doesn't match anything,
problem is this, i have a property in entity: public bool Expired { get
I have such an enum and a property. public enum Type { Hourly =
I wrote this function to communicate with an external program. Such program takes input
How can I write this in such a way that $counter value is 1
I need to configure a property of a custom control I wrote, specifically before
For a column of type varchar I could write such search query: public IList<Order>
I am currently using the following code to access the property of an object
I have some complicated object, such as a Cat, which has many properties, such
I've binded the tooltip of a slider control to it's Value property and i'm

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.