Skip to main content
added 139 characters in body
Source Link
Thomas Bratt
  • 52.3k
  • 36
  • 126
  • 143

A short summary of each:

Classes Only:

  • Can support inheritance
  • Are reference (pointer) types
  • The reference can be null
  • Have memory overhead per new instance

Structs Only:

  • Cannot support inheritance
  • Are value types
  • Are passed by value (like integers)
  • Cannot have a null reference (unless Nullable is used)
  • Do not have a memory overhead per new instance - unless 'boxed'

Both Classes and Structs:

  • Are compound data types typically used to contain a few variables that have some logical relationship
  • Can contain methods and events
  • Can support interfaces

A short summary of each:

Classes Only:

  • Can support inheritance
  • Are reference types
  • Have memory overhead per new instance

Structs Only:

  • Cannot support inheritance
  • Are value types
  • Do not have a memory overhead per new instance - unless 'boxed'

Both Classes and Structs:

  • Are compound data types typically used to contain a few variables that have some logical relationship
  • Can contain methods and events
  • Can support interfaces

A short summary of each:

Classes Only:

  • Can support inheritance
  • Are reference (pointer) types
  • The reference can be null
  • Have memory overhead per new instance

Structs Only:

  • Cannot support inheritance
  • Are value types
  • Are passed by value (like integers)
  • Cannot have a null reference (unless Nullable is used)
  • Do not have a memory overhead per new instance - unless 'boxed'

Both Classes and Structs:

  • Are compound data types typically used to contain a few variables that have some logical relationship
  • Can contain methods and events
  • Can support interfaces
Added comment about memory overhead of reference types.
Source Link
Thomas Bratt
  • 52.3k
  • 36
  • 126
  • 143

A short summary of each, with differences highlighted in italics:

Classes Only:

  • Can support inheritance
  • Are reference types and so are always allocated on the heap
  • Have memory overhead per new instance

Structs Only:

  • Cannot support inheritance
  • Are value types and so are allocated on the stack,
  • Do not have a memory overhead per new instance - unless boxed'boxed'

Both Classes and Structs:

  • Are compound data types typically used to contain a few variables that have some logical relationship
  • Can contain methods and events
  • Can support interfaces

A short summary of each, with differences highlighted in italics:

Classes Only:

  • Can support inheritance
  • Are reference types and so are always allocated on the heap

Structs Only:

  • Cannot support inheritance
  • Are value types and so are allocated on the stack, unless boxed

Both Classes and Structs:

  • Are compound data types typically used to contain a few variables that have some logical relationship
  • Can contain methods and events
  • Can support interfaces

A short summary of each:

Classes Only:

  • Can support inheritance
  • Are reference types
  • Have memory overhead per new instance

Structs Only:

  • Cannot support inheritance
  • Are value types
  • Do not have a memory overhead per new instance - unless 'boxed'

Both Classes and Structs:

  • Are compound data types typically used to contain a few variables that have some logical relationship
  • Can contain methods and events
  • Can support interfaces
Changed formatting and layout to make answer clearer to read.
Source Link
Thomas Bratt
  • 52.3k
  • 36
  • 126
  • 143

A short summary of each, with differences highlighted in italics:

Classes:

Classes Only:

  • Are compound data types typically used to contain a few variables that have some logical relationshipCan support inheritance
  • Can contain methodsAre reference types and eventsso are always allocated on the heap
  • Can support interfaces

Structs Only:

  • Can support inheritance Cannot support inheritance
  • Are reference types and so are always allocated on the heap Are value types and so are allocated on the stack, unless boxed

Structs:

Both Classes and Structs:

  • Are compound data types typically used to contain a few variables that have some logical relationship
  • Can contain methods and events
  • Can support interfaces
  • Cannot support inheritance
  • Are value types and so are allocated on the stack, unless boxed

A short summary of each, with differences highlighted in italics:

Classes:

  • Are compound data types typically used to contain a few variables that have some logical relationship
  • Can contain methods and events
  • Can support interfaces
  • Can support inheritance
  • Are reference types and so are always allocated on the heap

Structs:

  • Are compound data types typically used to contain a few variables that have some logical relationship
  • Can contain methods and events
  • Can support interfaces
  • Cannot support inheritance
  • Are value types and so are allocated on the stack, unless boxed

A short summary of each, with differences highlighted in italics:

Classes Only:

  • Can support inheritance
  • Are reference types and so are always allocated on the heap

Structs Only:

  • Cannot support inheritance
  • Are value types and so are allocated on the stack, unless boxed

Both Classes and Structs:

  • Are compound data types typically used to contain a few variables that have some logical relationship
  • Can contain methods and events
  • Can support interfaces
Source Link
Thomas Bratt
  • 52.3k
  • 36
  • 126
  • 143
Loading