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

What are Circular...

Câu trả lời

Circular references in C# occur when two or more classes or components depend on each other, creating a circular dependency that can lead to a lock condition and make the resources unusable[1]. This problem arises when classes have properties that reference each other, such as:

public class Pet { Dog petName; }
public class Dog { Pet petName; }

Here, Pet has a Dog property and Dog has a Pet property, causing a circular reference[1].

To avoid circular references, you can introduce an interface that both classes depend on instead of referencing each other directly[1][2]. For example:

public interface IBridge {}
public class Pet : IBridge { Dog petName; }
public class Dog : IBridge { Pet petName; }

Now Dog depends on Pet and IBridge, while Pet depends on Dog and IBridge, breaking the circular dependency[1].

Circular references can also be handled ...

expert

expert

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

expert

What is the use of static constructors?

junior

Can multiple catch blocks be executed?

expert

Explain what is Weak Reference in C#?

Bình luận

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

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