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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T22:05:27+00:00 2026-05-29T22:05:27+00:00

Say I had a very simple struct in c# public struct foo{ public int

  • 0

Say I had a very simple struct in c#

   public struct foo{
   public  int a{get;set;}
   public  int b{get;set;}
   public  int c{get;set;}
   public  int d{get;set;}
   public  string hello {get;set;}
   }

I take it the above is more ‘efficient’ than using a class?

At what point, if I continued to add string properties, would it be time to convert the struct to a class?

Edit: I had planned to pass this struct around a GDI – centric application.
I had always assumed structs were more performant when dealing with mainly value types.

  • 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-29T22:05:28+00:00Added an answer on May 29, 2026 at 10:05 pm

    If you need the enhanced capabilities that a class offers, such as inheritance, then switch. If not, a struct can be a bit “lighter,” but unless you anticipate some performance issues, such as garbage collection inside of a tight loop with a LOT of iterations, the necessity to pass structs around with ref whenever you want a method to make modifications, etc can create unnecessary work. (Though, in that example, destroying a struct that has reference-type properties also causes GC).

    The practical upshot being: whether to use a struct or a class is a matter of your use case, not the number of properties that you have.

    For a good explanation of the differences between and relative strengths and weakness of classes and structs, see this MSDN article.

    For Eric Lippert’s excellent note on garbage collection, structs and classes, see his response to this question.

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

Sidebar

Related Questions

This is probably a very simple question. Say I had a class that computed
say I had a stored proc like this: BEGIN DECLARE user_id INT; SET user_id
Say I had the following code: % Cellmode_subfunction_test.m %% Cell 1 foo(1); %% Cell
I am very new to Apache and .htaccess, and I had a simple question
Say I had the following HTML: <h2>Heading <span></span></h2> <ul> <li><a href=# title=I am wanting
Say I had (foolishly) setup a Silverlight project in VS and failed to setup
Let's say I had a program in C# that did something computationally expensive, like
Let's say you had to calculate the sine (cosine or tangent - whatever) where
Let's say I had: protected void performLogic(List<Object> docs) { ... } In the code
I'm having difficulties with multiple joins in the NHibernate Criteria search. Say I had

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.