I assume you want to store a mapping of all players and their respective starting point coordinates in the dictionary. The code for this would look like:
Dictionary<int, string> startingpoints = xml.Elements(ns + "startingPoint")
.Select(sp => new {
Player = (int)(sp.Attribute("player")),
Coordinates = (string)(sp.Attribute("coordinates"))
})
.ToDictionary(sp => sp.Player, sp => sp.Coordinates);
Even better, you had a class for storing the coordinates, like:
class Coordinate{
public int X { get; set; }
public int Y { get; set; }
public Coordinate(int x, int y){
X = x;
Y = y;
}
public static FromString(string coord){
try
{
// Parse comma delimited integers
int[] coords = coord.Split(',').Select(x => int.Parse(x.Trim())).ToArray();
return new Coordinate(coords[0], coords[1]);
}
catch
{
// Some defined default value, if the format was incorrect
return new Coordinate(0, 0);
}
}
}
Then you could parse the string into coordinates right away:
Dictionary<int, string> startingpoints = xml.Elements(ns + "startingPoint")
.Select(sp => new {
Player = (int)(sp.Attribute("player")),
Coordinates = Coordinate.FromString((string)(sp.Attribute("coordinates")))
})
.ToDictionary(sp => sp.Player, sp => sp.Coordinates);
You could then access the players coordinates like this:
Console.WriteLine(string.Format("Player 1: X = {0}, Y = {1}",
startingpoints[1].X,
startingpoints[1].Y));