πŸ“’ Too many exams? Don’t know which one suits you best? Book Your Free Expert πŸ‘‰ call Now!

  • google app store apple app store
  • βœ–

      Question

      In .NET (C#), what is the difference between 'struct'

      and 'class'?
      A struct supports inheritance; class does not Correct Answer Incorrect Answer
      B struct is a reference type stored on the heap; class is a value type stored on the stack Correct Answer Incorrect Answer
      C struct is a value type stored on the stack; class is a reference type stored on the heap Correct Answer Incorrect Answer
      D struct cannot have methods; class can have methods Correct Answer Incorrect Answer
      E There is no practical difference in modern .NET Correct Answer Incorrect Answer

      Solution

      In C#, struct is a value type. Copying a struct creates an independent copy (passed by value). class is a reference type. Variables hold references to heap-allocated objects (passed by reference). Structs are suitable for small, simple data (coordinates, RGB color) where value semantics are desired. Classes are used for complex objects with identity. Structs cannot be null (unless Nullable) and do not support inheritance, unlike classes.

      Practice Next

      Relevant for Exams:

      ask-question