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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T02:25:25+00:00 2026-05-17T02:25:25+00:00

Whenever I tried to search about differences between classes and structs in C# or

  • 0

Whenever I tried to search about differences between classes and structs in C# or .net, I ended up with the conceptual overview of the two things like value type or the reference type, where the variables are allocated etc. But I need some practical differences. I have found some like different behavior of assignment operator, having constructors etc. Can anybody provide some more practical differences which will be directly useful while coding? Like the things works with one but not with other or same operation showing different behavior. And some common mistakes regarding these two.

Also please suggest where to consider using a struct instead of a class. And where the structs should not be used.

Edit:
Do I have to call the constructor explicitly or just declaring a struct type variable will suffice?(Should I make it a new question?)

  • 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-17T02:25:26+00:00Added an answer on May 17, 2026 at 2:25 am

    OK, here are a few specific, practical differences:

    • A variable can be null if it’s a class, but is never null if it’s a struct.

    • default(T) is null for a class, but for a struct actually constructs a value (consisting of lots of binary zeros).

    • A struct can be made nullable by using Nullable<T> or T?. A class cannot be used for the T in Nullable<T> or T?.

    • A struct always has a public default constructor (a constructor with zero parameters). The programmer cannot override this constructor with a custom implementation — it is basically “set in stone”. A class allows the programmer to have no default constructor (or a private one).

    • The fields in a class can have default values declared on them. In a struct they can’t.

    • A class can inherit from another class, but a struct cannot be declared to derive from anything (it implicitly derives from System.ValueType).

    • It makes sense to use a class in object.ReferenceEquals(), but using a struct variable will always yield false.

    • It makes sense to use a class in a lock() statement, but using a struct variable will cause very subtle failure. The code will not be locked.

    • On a 32-bit system, you can theoretically allocate an array of up to 536,870,912 references to a class, but for a struct you need to take the size of the struct into account because you are allocating actual instances.

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

Sidebar

Related Questions

I have an asp.net TextBox control on my page and a search button whenever
I am running two erlang nodes with a replicated mnesia database. Whenever I tried
I using PHPUnit and Selenium Server to testing Yii Application, but whenever i tried
I dont know whether this simple task or not, but I tried to search
Basically I have an asp.net website with login and search pages. Currently, I have
The following code currently only generates a search query whenever a keyup event happens.
I have tried on two different machines, and tried the download several times, but
Whenever I tried to open rc file in VC++ 2008, I get this error
I purchased a domain: josecvega.com Whenever someone tries to access http://www.josecvega.com it forwards them
There is site , shop.test.com.au (not a real name) when ever i tried to

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.