Advertisement
ivandrofly

What's the difference between struct and class in .NET?

Apr 27th, 2015
430
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.80 KB | None | 0 0
  1. 42
  2. down vote
  3. A short summary of each:
  4.  
  5. Classes Only:
  6.  
  7. Can support inheritance
  8. Are reference (pointer) types
  9. The reference can be null
  10. Have memory overhead per new instance
  11. Structs Only:
  12.  
  13. Cannot support inheritance
  14. Are value types
  15. Are passed by value (like integers)
  16. Cannot have a null reference (unless Nullable is used)
  17. Do not have a memory overhead per new instance - unless 'boxed'
  18. Both Classes and Structs:
  19.  
  20. Are compound data types typically used to contain a few variables that have some logical relationship
  21. Can contain methods and events
  22. Can support interfaces
  23.  
  24. Fount at:
  25. http://stackoverflow.com/questions/13049/whats-the-difference-between-struct-and-class-in-net
  26. http://geekswithblogs.net/BlackRabbitCoder/archive/2010/07/29/c-fundamentals-the-differences-between-struct-and-class.aspx
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement