public static void Main(string[] args) { Console.Title = "Graph"; Vertex jana = new Vertex(); Vertex philip = new Vertex(); Vertex markus = new Vertex(); Edge relMarkusPhilip = new Edge(); Edge relJanaPhilip= new Edge(); jana.Data.Add("Class", "Person"); philip.Data.Add("Class", "Person"); markus.Data.Add("Class", "Person"); jana.Data.Add("Name", "Jana"); philip.Data.Add("Name", "Philip"); markus.Data.Add("Name", "Markus"); relJanaPhilip.Data.Add("Class", "Friend"); relMarkusPhilip.Data.Add("Class", "Friend"); relMarkusPhilip.ConnectVertices(ref markus, ref philip); relJanaPhilip.ConnectVertices(ref jana, ref philip); List<Edge> results = markus.SearchVertices("Friend"); foreach (Edge e in results) Console.WriteLine(e.Data["Class"]); Console.ReadLine(); }
// Methods public void ConnectVertices(ref Vertex firstVertex, ref Vertex secondVertex) { // Assign to local vertices FirstVertex = firstVertex; SecondVertex = secondVertex; // Assign to referred vertices firstVertex.Edges.Add(this); secondVertex.Edges.Add(this); }