Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/ms-access/4.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#_Code Contracts - Fatal编程技术网

在C#代码契约中使用纯函数时的静态验证限制?

在C#代码契约中使用纯函数时的静态验证限制?,c#,code-contracts,C#,Code Contracts,我试图静态地验证以下代码契约的基于数组的堆栈的部分实现。方法Pop()使用纯函数IsNotEmpty()。静态验证器失败,建议我添加先决条件契约。需要(0这应该可以解决问题: [Pure] public bool IsNotEmpty() { Contract.Ensures(Contract.Result<bool>() && 0 <= this.top || !Contract.Result<bool>() && 0 &g

我试图静态地验证以下代码契约的基于数组的堆栈的部分实现。方法
Pop()
使用纯函数
IsNotEmpty()。静态验证器失败,建议我添加先决条件
契约。需要(0这应该可以解决问题:

[Pure]
public bool IsNotEmpty() {
    Contract.Ensures(Contract.Result<bool>() && 0 <= this.top || !Contract.Result<bool>() && 0 > this.top);
    return 0 <= this.top;
}
[纯]
公共图书馆不是空的{
Contract.survey(Contract.Result()&&0 this.top);

返回0我个人对代码契约有点失望…ChaosPandion,有什么好失望的?即使类没有标记为密封,继承类也不能重写IsNotEmpty,因为它没有标记为虚拟,所以没有问题。谢谢Rich,你知道属性的行为为何是d吗不同的是,条件更简单地写为:
Contract.Result()==(0
[Pure]
public bool IsNotEmpty() {
    Contract.Ensures(Contract.Result<bool>() && 0 <= this.top || !Contract.Result<bool>() && 0 > this.top);
    return 0 <= this.top;
}