2

I am a beginner at .NET and C# programming and therefore my questions may be a little obscured. But nevertheless I try to ask for help this community.

I am programming a circular linked list using this article as help. I understand the main idea, but few things are incomprehensible for me.

  1. An author says in the beginning, that our list must "maintain collection semantics". Couldn't you explain, what is this collection semantics? As I understand, it is a set of some interfaces that must be implemented in our class. Is it true? And if yes – what exactly must we maintain in this class and why? Are these two interfaces in the article (ICollection, IEnumerable) enough, or these are only the most necessary ones?
  2. In a function that searches for a node with a given value

    public Node<T> Find(T item)
    {
        Node<T> node = FindNode(head, item);
        return node;
    }
    
    Node<T> FindNode(Node<T> node, T valueToCompare)
    {
        Node<T> result = null;
        if (comparer.Equals(node.Value, valueToCompare))
            result = node;
        else if (result == null && node.Next != head)
            result = FindNode(node.Next, valueToCompare);
        return result;
    }
    

    an author uses an IEqualityComparer<T> comparer object, which is initialized with a property EqualityComparer<T>.Default in one of constructors. Can you please explain me an idea of using of these interface (IEqualityComparer<T>) and class (EqualityComparer<T>) here? I had read MSDN, but I didn't understand the principles of working and using of them.

If my questions are too general, couldn't you suggest me some resources I might look through to find answers myself and streamline concepts in my mind?

  • 2
    Please ask one question per post... It is very hard to answer 2 very different questions with one concrete answer. – Alexei Levenkov Oct 05 '14 at 00:54
  • 1
    If I were you I'd drop the first, second, and final paragraphs. They don't add to the question greatly. Then post 1. & 2. as separate questions - and add back in the fact that you're writing a circular linked list. – Enigmativity Oct 05 '14 at 00:57
  • 1
    Damn, I've almost finished writing a detailed answer... That's frustrating. It's not too broad in my opinion overall even if it could be split in half. – Lucas Trzesniewski Oct 05 '14 at 01:02
  • 1
    Done. Separate question about semantics is [here](http://stackoverflow.com/questions/26202036/what-is-a-collection-semantics-in-net). Either one will be in 90 minutes. @Enigmativity – Mstislav Toivonen Oct 05 '14 at 11:14
  • 1
    Either question is [here](http://stackoverflow.com/questions/26202921/using-of-iequalitycomparert-interface-and-equalitycomparert-class-in-c-sharp). – Mstislav Toivonen Oct 05 '14 at 13:21

0 Answers0