C# 共同合同中的先决条件和后决条件
如果我写C# 共同合同中的先决条件和后决条件,c#,code-contracts,C#,Code Contracts,如果我写 [Pure] static string s10 {get;set;} static void Main(string[] args) { Contract.Ensures(s10.Length <= 10); //Contract fails s10 = ";uhlakushdflausgdflasgdfljgaskdjgfasd"; } [纯] 静态字符串s10{get;set;} 静态void Main(字符串[]参数) { 契约。确保(s
[Pure]
static string s10 {get;set;}
static void Main(string[] args)
{
Contract.Ensures(s10.Length <= 10); //Contract fails
s10 = ";uhlakushdflausgdflasgdfljgaskdjgfasd";
}
[纯]
静态字符串s10{get;set;}
静态void Main(字符串[]参数)
{
契约。确保(s10.Length是-代码契约重写器将代码移动到适当的位置,以及其他一些事情。值得在Reflector中查看结果以了解发生了什么
我强烈建议您彻底阅读代码契约随附的用户指南。据我所知,这是一份非常好的文档。是的。使用Req和Ens创建一个(更简单的)方法,并使用调试器逐步完成。您可以准确地跟踪重写器的效果。
[Pure]
static string s10 {get;set;}
static void Main(string[] args)
{
Contract.Requires(s10.Length <= 10); //NullReferenceException
s10 = ";uhlakushdflausgdflasgdfljgaskdjgfasd";
}