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:

csharp Copy
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:

csharp Copy
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

senior

What interface should your data structure implement to make the Where method work?

senior

Explain the difference between Select and Where

senior

Why to use lock statement in C#?

Bình luận

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

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