Class VS structure
Following are the similarities between classes and structures:-
1) Both can have constructors, methods, properties, fields, constants, enumerations, events, and event handlers.
2) Structures and classes can implement interface.
3) Both of them can have constructors with and without parameter.
4) Both can have delegates and events.
Following are the key differences between them:-
1) Structures are value types and classes are reference types.
2) Structures use stack and classes use heap.
3) Structures members cannot be declared as protected, but class members can be.
4) You cannot do inheritance in structures.
5) Structures do not require constructors while classes require.
6) Objects created from classes are terminated using Garbage collector. Structures are not destroyed using GC.
No comments:
Post a Comment