Tutorial by Examples

namespace CodeContractsDemo { using System; using System.Collections.Generic; using System.Diagnostics.Contracts; public class PaymentProcessor { private List<Payment> _payments = new List<Payment>(); public void Add(Payment payment) ...
public double GetPaymentsTotal(string name) { Contract.Ensures(Contract.Result<double>() >= 0); double total = 0.0; foreach (var payment in this._payments) { if (string.Equals(payment.Name, name)) { total += payment.Amount; } } ...
namespace CodeContractsDemo { using System; using System.Diagnostics.Contracts; public class Point { public int X { get; set; } public int Y { get; set; } public Point() { } public Point(int x, int y) { ...
[ContractClass(typeof(ValidationContract))] interface IValidation { string CustomerID{get;set;} string Password{get;set;} } [ContractClassFor(typeof(IValidation))] sealed class ValidationContract:IValidation { string IValidation.CustomerID { [Pure] get ...

Page 1 of 1