Alright I'm having a heck of a time figuring out what's wrong with this code. It throws an error of
Error 1 'System.Collections.Generic.Dictionary<Assignment7.Station,int>' does not contain a definition for 'ElementAt' and the best extension method overload 'System.Linq.Enumerable.ElementAt<TSource>(System.Collections.Generic.IEnumerable<TSource>, int)' has some invalid arguments7
However, when I was writing the code I followed the definition exactly... if someone could enlighten me I'd be grateful.
Code follows
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Assignment7
{
class SubwaySystem
{
//attributes
Dictionary<Station, int> stationDictionary = new Dictionary<Station,int>();
//methods
/**
* Inserts a new station ahead of one with the given ID
**/
void InsertAhead(int id, Station insert)
{
if (stationDictionary.ElementAt<Station>(id) == null)
Console.WriteLine("There is no element at the given ID.");
else
if (stationDictionary.ElementAt<Station>(insert.StID) != null)
Console.WriteLine("The ID of the station being added already exists.");
else
{
if (stationDictionary.Count == 0)
{
stationDictionary.Add(insert, insert.StID);
insert.Next = insert;
insert.Previous = insert;
}
else
{
stationDictionary.Add(insert, id);
insert.Next = stationDictionary.ElementAt<Station>(id).Next;
insert.Previous = stationDictionary.ElementAt<Station>(id);
insert.Next.Previous = insert;
insert.Previous.Next = insert;
}
}
}//End InsertAhead
/**
* Inserts a new station before one with the given ID
**/
void InsertBehind(int id, Station insert)
{
if (stationDictionary.ElementAt<Station>(id) == null)
Console.WriteLine("There is no element at the given ID.");
else
if (stationDictionary.ElementAt<Station>(insert.StID) != null)
Console.WriteLine("The ID of the station being added already exists.");
else
{
if (stationDictionary.Count == 0)
{
stationDictionary.Add(insert, insert.StID);
insert.Next = insert;
insert.Previous = insert;
}
else
{
insert.Next = stationDictionary.ElementAt<Station>(id);
insert.Previous = stationDictionary.ElementAt<Station>(id).Previous;
insert.Next.Previous = insert;
insert.Previous.Next = insert;
}
}
}
/**
* Removes station with specified ID
**/
void RemoveStation(int id)
{
}
/**
* Starts at the station with the specified id, following the references forward around the subway line,
* writing the station name and id until returning to the starting station.
**/
void TraverseSubwayLine(int startId)
{
}
static void Main(string[] args)
{
}
}
}