Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8680991
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T21:23:24+00:00 2026-06-12T21:23:24+00:00

I am writing a class for working with undirected graphs, and encountered the following

  • 0

I am writing a class for working with undirected graphs, and encountered the following compile-time errors:

The best overloaded method match for
‘Dictionary.EdgeCollection>.Add(TVertex, UndirectedGraph.EdgeCollection)’
has some invalid arguments

Argument 2: cannot convert
from UndirectedGraph<TVertex,TEdge>.AdjacentEdgeCollection<TVertex,TEdge>
to UndirectedGraph<TVertex,TEdge>.AdjacentEdgeCollection<TVertex,TEdge>

I could reduce the problem to the following example:

public class UndirectedGraph<TVertex, TEdge>
{
    Dictionary<TVertex, EdgeCollection<TVertex, TEdge>> edges;

    class VertexCollection<TVertex, TEdge>
    {
        UndirectedGraph<TVertex, TEdge> graph;

        public VertexCollection(UndirectedGraph<TVertex, TEdge> graph)
        { this.graph = graph; }

        public void Add(TVertex value)
        {
            // Argument 2: cannot convert
            // from 'UndirectedGraph<TVertex,TEdge>.AdjacentEdgeCollection<TVertex,TEdge>'
            //   to 'UndirectedGraph<TVertex,TEdge>.AdjacentEdgeCollection<TVertex,TEdge>'
            this.graph.edges.Add(value, new EdgeCollection<TVertex, TEdge>(this.graph));
        }
    }

    class EdgeCollection<TVertex, TEdge>
    {
        public EdgeCollection(UndirectedGraph<TVertex, TEdge> graph) { }
    }
}

Note that TVertex and TEdge in the nested classes are different from TVertex and TEdge in the outer class, and I get warnings stating that I should rename them. I can do that, but this does not affect the errors. I think the purpose of the fragment is clear, so how do I get it to do what I want and where does my thinking go wrong?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T21:23:25+00:00Added an answer on June 12, 2026 at 9:23 pm

    Are you sure that there are three TVertex type parameters and three TEdge type parameters? It seems to me that that all three are same and what you need is the following:

    public class UndirectedGraph<TVertex, TEdge>
    {
        Dictionary<TVertex, EdgeCollection> edges;
    
        class VertexCollection
        {
            UndirectedGraph<TVertex, TEdge> graph;
    
            public VertexCollection(UndirectedGraph<TVertex, TEdge> graph)
            { this.graph = graph; }
    
            public void Add(TVertex value)
            {
                this.graph.edges.Add(value, new EdgeCollection(this.graph));
            }
        }
    
        class EdgeCollection
        {
            public EdgeCollection(UndirectedGraph<TVertex, TEdge> graph) { }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm working on writing some constraints for a class method using PyContract (not PyContracts
I'm working on writing my own string class and am having trouble with overloading
I am writing a class library in C# for working with matrices, and am
I've been working on writing a library in my spare time to familiarize myself
I'm working on writing a tweening class in as2 that has a callback variable
I am working on writing a high-performance data retrieval/storage class for my application that
I am writing a template of a working class, and this might just be
I had working on a class and started writing everything in the same .cpp
For the iOS app I'm working on, I'm currently writing a singleton class that
I'm working in a CakePHP Model class, writing a function that is supposed to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.