What s the difference between struct and class in NET

0 votes
What's the difference between struct and class in .NET?
Feb 8 in Others by Rahul
• 8,980 points
20 views

1 answer to this question.

0 votes

In .NET, there are two categories of types known as the reference types and the value types. The Structs come under the category of value types and classes come under the reference types category. The known difference is that a reference type will live on the heap whereas a value type will live in line which means that wherever your variable is explained. A value type containing a variable includes the entire value type value which, in accordance to a struct, refers to a variable which contains the entire struct including all its fields. A reference type containing a variable includes a reference to another part in the storage where the actual value will exist. There is an advantage for this as the value types will always have a value included and a reference type will also have a null-reference included which means it does not refer to anything at the moment. Intrinsically, the reference types are implemented as pointers and knowing how variable assignment works, there are other behavioral patterns:

  • By copying the contents of a value type variable into another variable, it copies the entire content into a new variable which makes the two variables very distinct. In other words, after copying it, the changes to one will not affect the other one.
     

  • By copying the contents of a reference type variable into another variable, it will copy the reference, which states that you now have two references to the same somewhere else storage of the actual data. In other words, after copying it the changes in the data in one reference will appear to affect the other as well, but that is only because you are currently looking at the same data at both the places. 


When you will declare your variables, the value type will live on the stack and the reference type will live on the stack as a pointer to somewhere in the heap storage where the actual memory lives 

answered Feb 8 by Soham
• 8,730 points

Related Questions In Others

+1 vote
1 answer

what is the difference between error and stderr in Node.js?

Error is an object created by Node.js to handle ...READ MORE

answered Jul 4, 2019 in Others by sunshine
• 1,280 points
1,080 views
0 votes
1 answer

What is the difference between POST and PUT in HTTP?

To answer your question, both of them ...READ MORE

answered Feb 11 in Others by Rahul
• 8,980 points
24 views
0 votes
1 answer

What is the difference between hadoop and google analytics ?

I will try and answer this as ...READ MORE

answered Aug 22, 2018 in Others by Frankie
• 9,830 points
754 views
0 votes
0 answers

Mention the difference between Data Driven Testing and Retesting?

Retesting:  It is a process of checking ...READ MORE

Feb 1, 2019 in Others by riya

closed Feb 1, 2019 by Omkar 1,473 views
0 votes
1 answer

How interactive graphs are generated in Tableau?

Lot of back end code is shared ...READ MORE

answered Apr 14, 2018 in Tableau by xyz
• 1,560 points
229 views
0 votes
1 answer

How to create a new R6 Class in R?

You have to first create an object ...READ MORE

answered Jul 5, 2018 in Data Analytics by DataKing99
• 8,240 points
683 views
0 votes
1 answer
0 votes
1 answer

What does the "map" method do in Ruby?

The .map method will take an object ...READ MORE

answered Feb 8 in Others by Soham
• 8,730 points
90 views
0 votes
1 answer
webinar REGISTER FOR FREE WEBINAR X
Send OTP
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP