Câu hỏi phỏng vấn C#
Câu hỏi

What is the difference between a class and a structure ?

Câu trả lời

Here is a concise answer to the C# interview question "What is the difference between a class and a structure?":

Classes vs Structures in C#

In C#, both classes and structures are reference types that allow you to define custom data types. However, there are some key differences between them:

Value Types vs Reference Types

  • Classes are reference types - when you create an instance of a class, you are actually creating a reference to an object in memory. Copying a class instance creates a new reference to the same object.
  • Structures are value types - when you create an instance of a struct, you are creating a new copy of the data. Copying a struct creates an independent copy of the data.

Default Initialization

  • Classes are initialized to null by default if not explicitly initialized.
  • Structs are initialized with default values for their members if not explicitly initialized.

Inheritance

  • **Cl...
junior

junior

Gợi ý câu hỏi phỏng vấn

senior

How to solve Circular Reference?

middle

What is Virtual Method in C#?

junior

What are Reference Types in C#?

Bình luận

Chưa có bình luận nào

Chưa có bình luận nào