5-6 years ago when i was in school, I had C as my programming language. And at that time, I read about struct and little bit about Classes.
At that time I had a concept that under struct we cannot declare functions and other such things.
Structure only allows value types and themself are also value types. And I was living under that same old age concepts.
3 days earlier when I had some conversation with my collegues they proved that struct can also contain function definations, constuctors any many more things against my thinking of
public struct abc
{
int a;
long b;
.... //No function nothing else can come here. Only variables
};
But in .net I saw DateTime Struct and it had functions constructors and everything against my years old concepts.
Then what makes difference between classes and struct if every thing can be done in struct.
I am sure there would be some big differences, due to which struct are still coming with .net rather than obsoleting it.
What are those differences.
And what other such concepts could a one have that changed everything.
As far as I can tell you are asking what are the differences between structs and classes in C#.
The key difference is that structs behave following value type semantics, classes behave according to reference type semantics.
Aside from that there are some minor restrictions on what you can put in a struct (such as no parameterless constructors and only interface inheritance), but that isn’t what’s important. These restrictions are fairly irrelevant really, you shouldn’t choose to use a struct just to prevent inheritance. What matters is the how the type behaves semantically and that is what you should focus on when choosing between a struct and a class.
Further information:
This question has some good answers that explain the difference in more detail.
The MSDN page on structs has some good information on the restrictions.
Eric Lippart has an interesting two part blog post (part1, part2) on the details of struct vs class.