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

expert

Explain the difference between IQueryable , ICollection , IList & IDictionary interfaces?

senior

What is the difference between is and as operators in C#?

junior

Can this be used within a Static method?

Bình luận

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

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