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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T05:46:39+00:00 2026-06-16T05:46:39+00:00

Microsoft has the following rules for using struct: Consider defining a structure instead of

  • 0

Microsoft has the following rules for using struct:

Consider defining a structure instead of a class if instances of the
type are small and commonly short-lived or are commonly embedded in
other objects.

Do not define a structure unless the type has all of the following characteristics:

  1. It logically represents a single value, similar to primitive types (integer, double, and so on).
  2. It has an instance size smaller than 16 bytes.
  3. It is immutable.
  4. It will not have to be boxed frequently.

As far as I understand, you create struct when you want a value-type behavior. Of course this gives you copying overhead when assigning and passing it to functions. But why would you follow #2 and #3? What if your value type is just too large? Moreover, I don’t understand why you would ever make an immutable type to be a value type. If the type is immutable, you would better save time for passing it by reference, since anyway it cannot be changed.

The reason that I’m asking is that I’m making a game, where objects have properties like Coordinates, Velocity etc. of the type Vector2d. The question is, should I make Vector2d immutable struct (wouldn’t that require tons of additional memory?), mutable struct (people say they are evil) or just class (I will have to always call vector.Clone() because otherwise I may unintentionally get two objects having same vector variable)

  • 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-16T05:46:40+00:00Added an answer on June 16, 2026 at 5:46 am

    Moreover, I don’t understand why you would ever make an immutable type to be a value type.

    The int type is an immutable type and is a perfect example of why you need immutable value types.

    Imagine if int were a reference type. It would be very expensive if you had to dereference every time you used an integer. This is in fact what happens when you use “boxed” integers (e.g. integers that are stored in a variable of type object). One of the improvements in .NET compared to Java is that collections can hold unboxed integers.

    If the type is immutable, you would better save time for passing it by reference

    Yes if it’s large and immutable then you would save time by passing it by reference. That is why the guidelines suggest that large types should be reference types.

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

Sidebar

Related Questions

*edit: I understand that stackoverflow has banned all questions regarding using Microsoft's Visio. I'm
My web application has the following class: public class DatabaseProvider { private readonly IDbConnection
From what I understand, using Wiki and this question I posted, Microsoft has its
I'm using an application which has the following line in it: ACCEPT_FILE_TYPES = re.compile('image/(gif|p?jpeg|(x-)?png)')
consider the following code: class A { friend class B; friend class C; };
I'm using MVC3 with Razor. I have the following helper: public static class ImageActionLinkHelper
Microsoft has a handy reference of the various controls in the System.Windows.Controls namespace and
Microsoft has announce that WindowsLiveID become a OpenID provider . I want implement it
Visio has been supporting UML diagrams for quite some time now. Microsoft has now
So, it looks like Microsoft has gone back to pushing Web Application Projects* in

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.