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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T04:11:18+00:00 2026-06-10T04:11:18+00:00

I have a case where a struct may be preferable to a class: contains

  • 0

I have a case where a struct may be preferable to a class:

  • contains 3 bools
  • is immutable
  • is never boxed

However, I would like to add a number of properties with only get access, which provide combinations of the mentioned 3 bools. For example, the bools are “Same”, “Forward”, and “Backward”. Properties would be “All”, “None”, “UniDirectional”, “BiDirectional”, and so forth, which can be determined from the former 3.

Will these properties increase the size of each instance of the struct on the stack, and thus make a class more appropriate? Or will it not affect the choice?

  • 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-10T04:11:19+00:00Added an answer on June 10, 2026 at 4:11 am

    Short answer:

    No, they do not.

    Long answer:

    No, they do not; but…

    Properties themselves are just regular methods but dressed in field-like syntax. Because methods only exist in one location in memory (because they’re the same for every object of that type) they do not affect the size of each instance. Note that virtual methods (including virtual properties) muddy this a bit as adding a new virtual method will increase the size of the vtable, however a vtable only exists once for each class; but this is moot because structs don’t have vtables in .NET (in C++ they do, but that’s because structs and classes are semantically identical).

    “Properties” can increase the memory size of a struct type, but only if the person who wrote them is unfamilar with “auto-properties”. C# 3.0 introduced automatically-implemented properties (or “auto-properties” for short), where a hidden field is created by the compiler for trivial getter/setter properties. The syntax is public PropertyName { get; set; }.

    Back on-topic: only instance member fields affect the size of a struct, unless you have overlapping fields when using a custom StructLayout (which is how you create unions in C#). Note that static members do not affect the size of an instance, however in VB the Static keyword, when used for a local variable, can affect instance size (despite the same word, “static”, local variables marked Static in VB are not in class static state).

    Finally, note that in .NET there are overheads associated with values, but these are inherent in the “Managed” nature of .NET, however they don’t apply to structs used in interop scenarios (i.e. pointer arithmetic and sizeof all work as they would under C/C++).

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

Sidebar

Related Questions

I have a C structure like this : typedef struct ip_esp_private { /* keep
I have a class that derives from a C struct. The class does not
I have what I would think is the most common case for processing a
So I may have a rather unique use case here, but I'm thinking it
I have a situation where I have a simple, immutable value type: public struct
I have a struct like this: typedef struct string { unsigned long length; unsigned
I have the following use case, a struct with some boolean and int variables
Here is the case. In the file fileA.c I have typedef struct MY_STRUCT {
I have a case statement that returns a date; case when (ma.first_active_date is not
I have a case where I check if a variable is undefined. in some

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.