本文整理汇总了C#中Address.ToDictionary方法的典型用法代码示例。如果您正苦于以下问题:C# Address.ToDictionary方法的具体用法?C# Address.ToDictionary怎么用?C# Address.ToDictionary使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Address
的用法示例。
在下文中一共展示了Address.ToDictionary方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Main
static void Main(string[] args)
{
string startPoint = Console.ReadLine().Substring(9);
string endPoint = Console.ReadLine().Substring(9);
int N = int.Parse(Console.ReadLine());
var addresses = new Address[N];
for (int i = 0; i < N; i++)
{
string stopName = Console.ReadLine();
addresses[i] = new Address(stopName);
}
int M = int.Parse(Console.ReadLine());
var links = new Link[M];
for (int i = 0; i < M; i++)
{
string route = Console.ReadLine();
var nodes = route.Split(new[] { ' ' }, 2).Select(x => x.Substring(9)).ToArray();
links[i] = new Link { A = nodes[0], B = nodes[1] };
}
build(links, addresses);
var bfs = new Dijkstra(addresses, startPoint);
var path = bfs.Path(endPoint);
if (path == null)
{
Console.WriteLine("IMPOSSIBLE");
}
else
{
var addressDictionary = addresses.ToDictionary(x => x.Id);
foreach (var stopArea in path)
{
var address = addressDictionary[stopArea];
Console.WriteLine(address.Fullname);
}
}
}
示例2: build
private static void build(Link[] links, Address[] addresses)
{
var nodes = addresses.ToDictionary(x => x.Id);
foreach (var link in links.GroupBy(x=>x.A))
{
var node = nodes[link.Key];
node.Neighbours = link.Select(x => x.B).ToArray();
}
}