(प्लस नाम Predicate
स्रोत कोड के पाठकों के लिए इच्छित उपयोग संचार), आप विभिन्न प्रतिनिधि प्रकार है कि हस्ताक्षर में समान हैं और प्रकार वापसी हो सकती है। उदाहरण के लिए:
namespace N
{
// Represents a method that takes in a string and checks to see
// if this string has some predicate (i.e. meets some criteria)
// or not.
internal delegate bool StringPredicate(string stringToTest);
// Represents a method that takes in a string representing a
// yes/no or true/false value and returns the boolean value which
// corresponds to this string
internal delegate bool BooleanParser(string stringToConvert);
}
उपरोक्त उदाहरण में, दो गैर-जेनेरिक प्रकारों में समान हस्ताक्षर और वापसी प्रकार होता है। (और वास्तव में Predicate<string>
और Func<string, bool>
के समान ही)। लेकिन जैसा कि मैंने इंगित करने की कोशिश की, दोनों का "अर्थ" अलग है।
यह कुछ हद तक अगर मैं दो वर्गों, class Car { string Color; decimal Price; }
और class Person { string FullName; decimal BodyMassIndex; }
, तो सिर्फ इसलिए कि उन दोनों को पकड़ कर एक string
और एक decimal
, इसका मतलब यह नहीं है कि वे "एक ही" प्रकार कर रहे हैं।
स्रोत
2013-02-23 21:40:31
@ सेन - अंतर इरादा संवाद में निहित है। जब मैं एक अनुमान का उपयोग करता हूं, तो मेरा मतलब है कि कोड के ब्लॉक को 'परीक्षण' के रूप में उपयोग करना और परीक्षण परिणाम के आधार पर कार्रवाई करना है। जब मैं 'Func' का उपयोग करता हूं, तो मुझे केवल एक फ़ंक्शन जरूरी करने की आवश्यकता होती है जो पैरामीटर लेता है और एक बूल देता है। –
Gishu
संभावित डुप्लिकेट [क्यों अनुमानित करने के बजाय Func ?] (Http://stackoverflow.com/questions/665494/why-funct-bool-instead-of-predicatet) –
abatishchev