【发布时间】:2014-01-19 13:41:25
【问题描述】:
我做了以下编程。运行应用程序显示错误消息:索引超出范围。必须是非负数且小于集合的大小。
编辑:
public void SetShortcuts()
{
List<string> Verknüpfung = new List<string>();
int i = 0;
int j = 0;
try
{
foreach (string Datei in Directory.GetFiles(PfadShortcuts, "*.txt"))
{
Verknüpfung.AddRange(File.ReadAllLines(Datei, Encoding.UTF8));
Image ShortcutIcon = new Image();
ShortcutIcon.Source = new BitmapImage(new Uri(@"Fugue Icons\document.png", UriKind.Relative));
ShortcutIcon.Height = 16;
ShortcutIcon.Width = 16;
ShortcutIcon.Stretch = Stretch.None;
MenuItem Shortcut = new MenuItem();
Shortcut.Icon = ShortcutIcon;
Shortcut.Header = Verknüpfung[0 + i];
Shortcut.Padding = new Thickness(5);
Shortcut.Click += delegate { Process.Start(Verknüpfung[0 + j]); };
Shortcuts.Items.Add(Shortcut);
i += 2;
j++;
}
}
catch
{
Fehlermeldung_Main_Shortcuts();
}
}
你能帮帮我吗? 提前致谢。
亲切的问候。
【问题讨论】:
-
你没有在任何地方检查我
-
谢谢。但为什么我需要这样做?在哪里?
-
不知道,因为你做错了,所以没有费心阅读你的代码。
-
@Shai 告诉某人他们做错了几乎和发布一个问题“它坏了,修复它”一样有用。当你甚至没有正确阅读它时,你怎么能说这一切都是错误的?如果一切都错了,那为什么不提供建议,让他学会解决问题并学会正确地做这一切呢?
标签: c# list collections click file.readalllines