Tag: 循环

for循环“索引超出范围”c#webdriver

我从这个循环得到“索引超出范围”。 但我需要使用循环创建的新元素,我该怎么做? 请帮助解决问题 int linkCount = driver.FindElements(By.CssSelector(“a[href]”)).Count; string[] links = new string[linkCount]; for (int i = 0; i < linkCount; i++) { List linksToClick = driver.FindElements(By.CssSelector(“a[href]”)).ToList(); links[i] = linksToClick[i].GetAttribute(“href”); }

如何在C#中重命名一个循环中的多个按钮

我有一个类似战舰的程序,其中有一个10 x 10网格的按钮。 在程序的开头,我希望所有按钮的文本都改为“—”,这表明没有人在那个坐标上射击。 我似乎无法找到一种方法来重命名一个循环中的所有按钮。 按钮都有名称b00,b01,b02 ……显示其坐标。 第一个数字是行,第二个数字是列。 (即b69代表第7行,第10列)。 希望你能帮忙! 先感谢您! 卢克

C#。 使用reflection设置成员对象值

我需要您的帮助,以下代码。 基本上我有一个名为“Job”的类,它有一些公共字段。 我传递给我的方法“ApplyFilter”两个参数“job_in”和“job_filters”。 第一个参数包含实际数据,第二个参数包含指令(如果有)。 我需要遍历“job_in”对象,读取它的数据,通过读取“job_filters”来应用任何指令,修改数据(如果需要)并将其返回到新的“job_out”对象中。 一切正常,直到我需要将我的数据存储在“job_out”对象中: public class Job { public string job_id = “”; public string description = “”; public string address = “”; public string details = “”; } … private Job ApplyFilters(Job job_in, Job job_filters) { Type type = typeof(Job); Job job_out = new Job(); FieldInfo[] fields = type.GetFields(); // iterate through […]

如何遍历treeView控件的所有节点。 C#

我正在选择form所有控件 如果控件是Treeviews ,我将迭代他们拥有的所有节点 我需要类似的东西:(这是我的代码) foreach (Control c in PanelSM.Controls) { if (c is TreeView) { TreeNodeCollection myNodes = c.Nodes;//<<<<< Here is a mistake foreach (TreeNode n in myNodes) { String text = rm.GetString(n.Name); //And more things //… //… //… } } //… } 任何的想法? 谢谢

IndexOutofRangeException是什么意思?

它说在我的数组中我已经超越了索引。 我的节目是5个玩家(5个索引)玩的数字猜测游戏。 我使用数组来创建对象和播放器类。 我已经到了一个残端,我的程序在第二轮或第三轮比赛中崩溃。 我注意到在第二轮中,索引没有循环属性:循环在第一个循环中计算索引1到5,然后在第二个循环中计数2到5,然后如果我甚至到达循环的第3轮,所有的索引都被洗牌,意思是我不能从1到5。 当每个玩家得到3个猜测时,使用这3个猜测和你的游戏。 我已经为播放器创建了一个对象数组,创建了一个比前一个更小的临时数组并引用它来实现当前数组。 我在代码中查看了我的引用,发现尽可能多的代码,我找不到导致我的System.IndexOutOfRangeException的错误。 这是由我的猜谜游戏课引起的。 这是我的GuessingGame课程: using System; // only this using statement is needed here. namespace GuessingGame { class GuessingGame { #region instance attributes private const int GUESSES_ALLOWED = 3; private const int NUMBER_OF_PLAYERS_TO_START = 5; private const int MIN_VALUE = 1; private const int MAX_VALUE = 15; private Player[] […]

在这种情况下,为什么使用AsParallel()比foreach慢?

我正在从这种格式的excel中提取数据 product1 | unnamedcol2 | product2 | unnamedcol4 | product3 | unnamedcol6 | ————————————————– —————————– @ 1foo | 1.10 | @ 1foo | 0.3 | @ 1foo | 0.3 @ 2foo | 1.00 | @ 2foo | 2 | @ 2foo | @ 3foo | 1.52 | @ 3foo | 2.53 | @ 3foo | […]

VB.NET中“yield return”的等价语法是什么?

使用下面的C#代码,您将如何在Visual Basic中编写它? 它想说什么? using System; using System.Collections.Generic; using System.IO; using System.Windows; using System.Windows.Media; using System.Windows.Media.Imaging; namespace Microsoft.LiveLabs.Pivot { /// /// Tile Builder class /// public static class TileBuilder { /// /// Specifies which images are required in the images array used in CreateTile /// according to the Morton fractal pattern used by Seadragon. /// /// […]

强制循环等待事件

我正在尝试编写一个遍历项目列表的方法 – 每个项目将其添加到表单中,然后等待用户输入一些数据并单击按钮。 但是我不知道我应该/可以使用什么来创建它。 foreach (string s in List) { txtName.Text = s; //wait for button click… // When the user is ready, they click the button to continue the loop. } 到目前为止,我发现的是EventWaitHandle类,它似乎只适用于线程。 我怎样才能做到这一点?

asp.net mvc razor foreach循环将id添加到div

我试图在与变量i值连接的foreach循环内向div添加动态id 。 它会引发语法错误。 可能是什么问题。 我们能不使用for循环来实现这个解决方案吗? @{int i=1;} @foreach (var or in Model.Names) { @or.Name i++; }

C#从Color中获取所有颜色

我想让ComboBox填充System.Drawing.Color所有颜色 但我似乎无法从该系列中收集所有颜色 我已经尝试过使用foreach来完成这样的工作: foreach (Color clr in Color) { } 但我得到的只是一个错误。 那我怎么能循环所有的颜色呢? 任何帮助将不胜感激。