Visual Studio
कोड अनुबंध
खोज…
टिप्पणियों
कोड कॉन्ट्रैक्ट से पूरी तरह से लाभ पाने के लिए आपको विजुअल स्टूडियो के लिए एक्सटेंशन इंस्टॉल करना होगा। एक कोड अनुबंध उपयोगकर्ता नियमावली भी है ।
मानक पूर्व शर्त
using System.Diagnostics.Contracts;
public int DivideNumbers(int numerator, int denominator)
{
Contract.Requires(denominator != 0);
return numerator / denominator;
}
पूर्वधारणा जो एक विशिष्ट अपवाद को फेंकता है
using System.Diagnostics.Contracts;
public int DivideNumbers(int numerator, int denominator)
{
Contract.Requires<ArgumentOutOfRangeException>(denominator != 0);
return numerator / denominator;
}
पूर्व और बाद के पद
using System.Diagnostics.Contracts;
public int IncrementByRandomAmount(int input)
{
Contract.Requires<ArgumentNullException>(input != null); // Don't allow null parameter.
Contract.Requires<ArgumentOutOfRangeException>(input < int.MaxValue); // We can't do anything if we're given int.MaxValue.
Contract.Ensures(Contract.Result<int>() > input); // Return value will be greater than input value.
Random rnd = new Random();
input += rnd.Next(1, 13); // Creates a number between 1 and 12 and adds it to input.
return input;
}
Modified text is an extract of the original Stack Overflow Documentation
के तहत लाइसेंस प्राप्त है CC BY-SA 3.0
से संबद्ध नहीं है Stack Overflow