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

  • Home
  • SEARCH
  • 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 757697
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T15:23:37+00:00 2026-05-14T15:23:37+00:00

I have a a polygon class which stores a list of Microsoft.Xna.Framework.Vector2 as the

  • 0

I have a a polygon class which stores a list of Microsoft.Xna.Framework.Vector2 as the vertices of the polygon. Once the polygon is created, I’d like other classes to be able to read the position of the vertices, but not change them.

I am currently exposing the vertices through this field:

/// <summary>
/// Gets the vertices stored for this polygon.
/// </summary>
public List<Vector2> Vertices
{
    get { return _vertices; }
}
List<Vector2> _vertices;

However you can change any vertex using code like:

Polygon1.Vertices[0] = new Vector2(0, 0);

or

Polygon1.Vertices[0].X = 0;

How can I limit other classes to be able to only read the properties of these vertices, and not be able to set a new one to my List? The only thing I can think of is to pass a copy to classes that request it.

Note that Vector2 is a struct that is part of the XNA framework and I cannot change it.

Thanks.

  • 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-14T15:23:38+00:00Added an answer on May 14, 2026 at 3:23 pm

    Have a readonly interface on your type (however since this is built in type), and pass out a version in a ReadOnlyCollection is for.

    public ReadOnlyCollection<IReadOnlyVector2> Vertices
    {
        get { return (from v in _vertices 
                      select new DerivedVector2 { WrappedVector2 = v })
                     .Cast<IReadOnlyVector2>().ToList().AsReadOnly(); 
         }
    }
    List<Vector2> _vertices;
    
    interface IReadOnlyVector2 {
     .. only RO getters and no setters
    }
    
    class DerivedVector2 : IReadOnlyVector2{
        public Vector2 WrappedVector2 { get; internal set;} 
    .
    .
    .
    

    }

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

Sidebar

Related Questions

I'm wondering something. I have class Polygon , which composes a vector of Line
I have a class Grid which produces a graph paper like grid on in
I have a class Polygon on which I wish to implement two iterators: one
I have a polygon soup of triangles that I would like to construct a
I have a Polygon (a Hex for a board game) in Silverlight, something like;
I have a class as follows: public class Polygon extends Shape{ private int noSides;
Here's a riddle for you. You have a polygon composed of exactly 4 vertices,
I have a login.jsp page which contains a login form. Once logged in the
I have a java class that looks like public class MyClass { private final
i have a polygon with some radius. Something like this . Now i need

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.