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 696261
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T03:02:42+00:00 2026-05-14T03:02:42+00:00

I’m wondering how you’d recommend designing a class, given the fact that XNA Framework

  • 0

I’m wondering how you’d recommend designing a class, given the fact that XNA Framework uses Struct all over the place?

For example, a spite class, which may require a Vector2 and a Rectangle (both defined as Struct) to be accessed outside of the class.

The issue come in when you try to write code like this:

class Item 
{
    public Vector2 Position {get; set;}
    public Item() { Position = new Vector2(5,5); }
}

Item i = new Item();
i.Positon.X = 20; // fails with error 'Cannot modify the return value of Item because it is not a variable.'

// you must write code like this
var pos = i.Position;
pos.X++;
i.Position = pos;

The second option compiles and works, but it is just butt ugly. Is there a better way?

  • 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-05-14T03:02:42+00:00Added an answer on May 14, 2026 at 3:02 am

    Or, just to throw this out there … just expose the field. There’s nothing inherently wrong with exposing a public field.

    For example, if your entity exposes a Vector3 for it’s position so that other things can use that value in their own calculations … just expose it. Otherwise, if no other class or entity needs to know the position, do not expose it at all 🙂

    Here is some sage advice from Rico Mariani:

    Generally, my feeling is that properties are highly overrated and fields terribly under-utilized. Did I mention that not everyone agrees with this position? 🙂

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

No related questions found

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.