What s the difference between struct and class in NET

0 votes
What's the difference between struct and class in .NET?
Feb 8, 2022 in Others by Rahul
• 9,680 points
445 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, 2022 by Soham
• 9,710 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,300 points
2,452 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, 2022 in Others by Rahul
• 9,680 points
790 views
0 votes
0 answers

What is the difference between iostream , stdio.h and conio.h header files in c++?

I am confused between all these three ...READ MORE

Sep 23, 2022 in Others by gaurav
• 23,260 points
1,539 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
1,636 views
0 votes
0 answers

What are the differences between struct and class in C++?

I now want to understand the distinctions ...READ MORE

Aug 17, 2022 in C++ by Nicholas
• 7,760 points
521 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
875 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,250 points
1,308 views
0 votes
1 answer

What does the "map" method do in Ruby?

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

answered Feb 8, 2022 in Others by Soham
• 9,710 points
1,170 views
0 votes
1 answer

The uploaded file exceeds the upload_max_filesize directive in php.ini error while uploading plugin

After looking at your ERROR, it seems ...READ MORE

answered Feb 8, 2022 in Others by Soham
• 9,710 points
702 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP