小编Dav*_*ell的帖子

为什么这个基于字符串的Contract.Ensure调用未经证实?

我的.Net 4应用程序中有以下代码:

static void Main(string[] args) {
    Func();
}

static string S = "1";

static void Func() {
    Contract.Ensures(S != Contract.OldValue(S));
    S = S + "1";
}
Run Code Online (Sandbox Code Playgroud)

这让我在编译时确保未经证实的警告:

warning : CodeContracts: ensures unproven: S != Contract.OldValue(S)
Run Code Online (Sandbox Code Playgroud)

到底是怎么回事?如果S是整数,这可以正常工作.如果我将Ensure更改为S == Contract.OldValue(S + "1"),它也可以工作,但这不是我想要做的.

c# .net-4.0 code-contracts

6
推荐指数
1
解决办法
295
查看次数

标签 统计

.net-4.0 ×1

c# ×1

code-contracts ×1