Tag: indexoutofboundsexception

填充数组以避免索引超出数组错误范围的方法

当我查询它时,我希望在我的列表中至少有183个项目,但有时候我的提取结果导致项目数低于183.我的当前修复假定在计数小于183的情况下填充数组。 if (extractArray.Count() < 183) { int arraysize= extractArray.Count(); var tempArr = new String[183 – arraysize]; List itemsList = extractArray.ToList(); itemsList.AddRange(tempArr); var values = itemsList.ToArray(); //– Process the new array that is now at least 183 in length } 但似乎我的解决方案不是最好的。 我将不胜感激任何其他解决方案可以帮助确保每当提取物发生时我至少得到183个项目。

在尝试启动多个线程时,索引超出了数组的范围

我有这个代码,它给了我一个“索引超出了数组的范围”。 我不知道为什么会发生这种情况,因为变量i应该总是小于数组bla的长度,因此不会导致此错误。 private void buttonDoSomething_Click(object sender, EventArgs e) { List t = new List(); string[] bla = textBoxBla.Lines; for (int i = 0; i some_thread_funmction(bla[i]))); t[i].Start(); } } 有人能告诉我如何解决这个问题,为什么会发生这种情况。 谢谢!

索引超出了数组exception的范围

这是我从平面文件中获取数据并插入SQL Server的代码。 它正在生成exception( Index was outside the bounds of the array )。 string path = string.Concat(Server.MapPath(“~/TempFiles/”), Fileupload1.FileName); string text = System.IO.File.ReadAllText(path); string[] lines = text.Split(‘ ‘); con.Open(); SqlCommand cmd = new SqlCommand(); string[] Values = new string[3]; foreach (string line1 in lines) { Values = line1.Split(‘;’); string query = “INSERT INTO demooo VALUES (‘” + […]

使用参数创建新线程时索引超出范围?

我正在研究关于烘焙算法的项目,但我没有在C#中使用该算法的任何演示。 由于这种情况,我已经转换了一些我在维基百科上找到的java代码。 但无论如何,它似乎不起作用! 更新 :这是我的全部工作代码(旧代码包含在“//”注释中) namespace BakeryAlgorithm { class Program { static int threads = 10; static string x = “”; static int count = 0; static int[] ticket = new int[threads]; static bool[] entering = new bool[threads]; public static void doLock(int pid) { entering[pid] = true; int max = 0; for (int i = […]