What are similarities between a class and a structure?

Technology CommunityCategory: OOPWhat are similarities between a class and a structure?
VietMX Staff asked 3 years ago

The following are some of the similarities between a class and a structure:

  • Access specifiers, such as publicprivate, and protected, are identically used in structures and classes to restrict the access of their data and methods outside their body.
  • The access level for class members and struct members, including nested classes and structs, is private by default. Private nested types are not accessible from outside the containing type.
  • Both can have constructors, methods, properties, fields, constants, enumerations, events, and event handlers.
  • Both structures and classes can implement interfaces to use multiple-inheritance in code.
  • Both structures and classes can have constructors with parameter.
  • Both structures and classes can have delegates and events.