确保Random.Next(Int32)合同的问题 [英] Problem ensuring contract for Random.Next(Int32)

查看:94
本文介绍了确保Random.Next(Int32)合同的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

System.Random.Next(Int32)  post condition 是"Contract.Result< int>()
< ; maxValue"。

System.Random.Next(Int32) post condition is "Contract.Result<int>() < maxValue".

但是< if  maxValue  等于零,  maxValue  返回"。 (MSDN)

but "if maxValue equals zero, maxValue is returned". (MSDN)

 

所以以下代码有效,但是CC会抛出ContractException。

 

    class Program
    {
        class MyRandom : Random
        {
            public override int Next(int maxValue)
            {
                return base.Next(maxValue);
            }
        }

        static void Main(string[] args)
        {
            var r = new MyRandom();
            var val = r.Next(0);
        }
    }

 

CC 1.4.31130.0

CC 1.4.31130.0

推荐答案

谢谢。我们确实注意到了这种差异,它应该已经在最新版本中得到修复。尝试升级。
Thanks. We did notice this discrepancy and it should already be fixed in the most recent release. Try to upgrade.


这篇关于确保Random.Next(Int32)合同的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆