我想在List中找到keyvaluepair元素,并且想不通如何通过“
无法将运算符==应用于类型的操作数 'System.Collections.Generic.List'
”错误。当我将方法更改为_adjacencyMatrix.FindIndex(from.GetNumer())时,我得到“
参数int不可分配给参数类型'System 。谓词
“然后,当我将方法更改为_adjacencyMatrix.IndexOf(MakePair(from,to))时,我得到了”
参数类型'System.Collections.Generic.keyvaluepair'不是 可分配给参数类型'System.Collections.Generic.List
”错误。我不知道该怎么办。你们有什么想法吗?尽管我在C ++中工作,但我还是C#的新手。我附上以下代码。可能应该有数字而不是数字,但我不想在代码中更改它。
using System.Windows.Documents;
namespace GPS
{
public class Vertex
{
private int _numer;
public Vertex(int numer)
{
this._numer = numer;
}
public void Deconstruct()
{
}
public int GetNumer()
{
return this._numer;
}
}
}
using System.Collections.Generic;
using GPS;
namespace GPS
{
public class Edge
{
private float _distance;
private keyvaluepair<Vertex,Vertex> _fromTo;
public Edge(float distance,keyvaluepair<Vertex,Vertex> fromTo)
{
this._distance = distance;
this._fromTo = fromTo;
}
public keyvaluepair<Vertex,Vertex> GetFromTo()
{
return _fromTo;
}
public float GetDistance()
{
return _distance;
}
public void SetDistance(float distance)
{
this._distance = distance;
}
public void Deconstruct()
{
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Configuration;
using System.Windows.Documents;
using GPS;
namespace GPS
{
public class Graph
{
private int _vertexNumber;
private List _egdesMatrix;
private List<List<Vertex>> _adjacencyMatrix;
public Graf(int vertexNumber)
{
this._vertexNumber = vertexNumber;
this._egdesMatrix = new List();
this._adjacencyMatrix = new List<List<Vertex>>();
}
public void Deconstruct()
{
}
public List GetEgdesMatrix()
{
return _egdesMatrix;
}
public bool IsOutOfRange(Vertex from,Vertex to)
{
return from.GetNumer() < 0 || to.GetNumer() < 0 ||
from.GetNumer() >= _vertexNumber || to.GetNumer() >= _iloscWierzcholkow;
}
private keyvaluepair<Vertex,Vertex> MakePair(Vertex from,Vertex to)
{
return new keyvaluepair<Vertex,Vertex>(from,to);
}
public bool IsThereAnEdge(Vertex from,Vertex to)
{
if (IsOutOfRange(from,to) != false) return false;
for (var i = 0; i < _vertexNumber; i++)
{
if (_adjacencyMatrix[from.GetNumer()]==to) ;
{
return true;
}
}
return false;
}
//list.Find(item => item > 20);
public void DodajKrawedz(Vertex from,Vertex to,float odleglosc)
{
if (IsOutOfRange(from,to) == false && IsThereAnEdge(from,to) == false)
{
_egdesMatrix.Add(MakePair(from,to));
}
}
}
}