Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/299.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 正确处理变量构造函数参数_C# - Fatal编程技术网

C# 正确处理变量构造函数参数

C# 正确处理变量构造函数参数,c#,C#,我有一个带构造函数的用户类 public class User{ public User(string name, string role, IWebElement submitButton) { this.Name = name; this.Role = role; this.SubmitButton = submitButton; } public string Name { get; private s

我有一个带构造函数的用户类

public class User{
    public User(string name, string role, IWebElement submitButton)
    {
         this.Name = name;
         this.Role = role;
         this.SubmitButton = submitButton;
    }

    public string Name { get; private set; }
    public string Role { get; private set; }
    public IWebElement SubmitButton { get; private set; }
}
此类表示selenium测试中的web元素表

var rowTds = rows[i].FindElements(By.TagName("td"));
User user;

if (rowTds.Count > 0)
{
    userRow = new UserRow(rowTds[0].Text, rowTds[1].Text, rowTds[2]);
}

我的目标是以这样一种方式编写上述代码,即如果rowTds发生更改,我的测试将不会中断。更好的解决方案是循环将元素添加到数组中,并向其他构造函数传递一个处理变量数组并使用前3个元素作为构造函数的数组吗?

如果在中读取标题信息,可以使用标题列为键的
字典。我不知道你的代码是如何工作的,你把
年龄
作为一个字符串传递,但不知怎么神奇地转换成了一个整数?@RonBeyer缺少年龄解析是一个错误,因为我的示例与我实际使用的有点不同。我想用一个更简单的例子,让它变得更糟!