下面的代码有时会返回意外的输出(至少对我来说)。
var arr1 = "john".split('');
var arr2 = arr1;
var arr3 = "jones".split('');
arr2.push(arr3);
console.log("array 1: length=" + arr1.length + " last=" + arr1.slice(-1));
Run Code Online (Sandbox Code Playgroud)
//返回[j,o,n,e,s]
而
console.log("array 1: length=" + arr1.length + " last=" + arr1.slice(-2));
Run Code Online (Sandbox Code Playgroud)
//返回[n,j,o,n,e,s]
此输出背后的逻辑是什么?
我使用 Moq 编写了以下类和测试类:
public class Mytest : testin
{
public int getId(int id)
{
int s = 2;
return s;
}
}
Run Code Online (Sandbox Code Playgroud)
测试类:
private Mock<testin> _mock;
[TestInitialize]
public void Setup()
{
_mock = new Mock<testin>();
}
[TestMethod]
public void returngetId()
{
// Build up our mock object
_mock.Setup(x => x.getId(It.IsAny<int>())).Returns(1)
}
Run Code Online (Sandbox Code Playgroud)
我从函数返回2,并在单元测试用例中检查值1。根据我的理解,测试用例应该失败。但我收到成功消息。我如何验证返回值正是我所期望的?如果它返回 1 以外的值,我希望测试失败。
由于从电子表格中获取数据,我返回了一个数据表。我只需要显示不同行的结果集仅取决于一列。
例如,我有一个带有列的数据表
id | name | age | email
Run Code Online (Sandbox Code Playgroud)
然后,如果列出了多个具有相同id 的记录,则应将其省略。我试过
dt = dt.DefaultView.ToTable(true)
Run Code Online (Sandbox Code Playgroud)
但它返回关于所有列的不同记录。我只需要基于 id 的不同记录。
谁可以帮我这个事?
我在我的应用程序中有以下代码.
public class GeneralInfo
{
private string _id;
private string _name;
public string id
{
set
{
_id = value;
}
get
{
return _id;
}
}
public string name
{
set
{
_name = value;
}
get
{
return _name;
}
}
}
public class SecureInfo
{
private string _password;
public string password
{
set
{
_password = value;
}
get
{
return _password;
}
}
}
public class User
{
}
Run Code Online (Sandbox Code Playgroud)
我需要在上面的代码中应用多重继承,即.应该可以在用户类中访问类GeneralInfo,SecureInfo属性.
我知道使用接口可以实现多重继承.但我需要在接口中限制的基类中定义属性.
我怎么能做到这一点?
c# ×3
.net ×1
asp.net ×1
inheritance ×1
interface ×1
javascript ×1
linq ×1
moq ×1
unit-testing ×1