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

What are Reference Types in C#?

Câu trả lời

Reference Types in C#

In C#, reference types are variables that store references to objects in memory. When you create an instance of a reference type, the variable holds a reference to the object's location in memory rather than the object itself. Here are the key points about reference types in C#:

1. Classes

Classes are the most common reference types in C#. When you create an instance of a class using the new keyword, a reference to the object is stored in the variable.

csharp Copy
MyClass obj = new MyClass();

2. Interfaces

Interfaces are also reference types. Variables of an interface type can hold references to objects that implement that interface.

csharp Copy
IMyInterface obj = new MyClass();

3. Delegates

Delegates are reference types that represent methods with a specific signature. They are used for event handling and callbacks.

csharp Copy
EventHandler obj = MyMethod;

4. Arrays

Arrays are reference types, even i...

junior

junior

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

middle

What is the difference between dynamic type variables and object type variables?

middle

What is the difference between Interface and Abstract Class?

junior

What are dynamic type variables in C#?

Bình luận

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

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