property within an interface of same name C#
Solution 1:
Here is what came to my mind first. Not sure if this answers your question though but let's say you are implementing a Linked list data structure. You will probably have some kind of a Node to represent the values in the list:
class LinkedList<INode>
{
public INode Head { get; set; }
}
interface INode
{
INode Next { get; set; }
}
class Node : INode
{
public object Value { get; set; }
public INode Next { get; set; }
}
The interface implementation can be used to ensure that the class will have a reference to itself in order to represent the next element in the linked list.
Solution 2:
There are plenty of use-cases where a type may have a property of itself. Imagine a Person
. Every instance of that class may have Children
, which themeselves Person
s as well and may have other Children
.
class Person
{
public Person Child;
}
In your case one may argue that a box may live within another box or may contain other boxes.
Or let´s think of a Box
as a surrounding rectangle around some geometric figure. Of course that bounding-box is a geometry in itself, so it may have a bounding-box also (which however will be pretty much the same).