What are circular references in C#?

CsharpProgrammingServer Side Programming

Circular reference occurs when two or more interdependent resources cause lock condition. This makes the resource unusable.

To handle the problem of circular references in C#, you should use garbage collection. It detects and collects circular references. The garbage collector begins with local and static and it marks each object that can be reached through their children.

Through this, you can handle the issues with circular references.

Let’s say the following classes is in circular reference. Here both of them depends on each other −

public class A {
   B Two;
}

public class B {
   A one;
}

To solve the issue, create an interface −

public interface myInterface {
}

public class A {
   myInterface Two;
}

public class B: myInterface {
   A one;
}
raja
Published on 10-Aug-2018 10:33:12
Advertisements