मैं समझता हूँ कि कैसे एक अंतरफलक लेखन करते हैं, सी # में काम करता है, उदाहरण के लिए के रूप में यहाँ वर्णित:सी # में इंटरफेस कास्टिंग क्या है?
Human human = new Human();
// The human object is casted to the interface type
IIntelligence humanIQ = (IIntelligence)human;
humanIQ.intelligent_behavior();
क्या है: codeguru explanation
interface IIntelligence
{
bool intelligent_behavior();
}
class Human: IIntelligence
{
public Human()
{
//.............
}
/// Interface method definition in the class that implements it
public bool intelligent_behavior()
{
Console.WriteLine("........");
return true
}
}
मैं तथापि इंटरफ़ेस कास्टिंग के निम्नलिखित प्रक्रिया के बारे में उलझन में हूँ इस मामले में कक्षा (मानव) की भावना है) एक इंटरफ़ेस लागू करें, और उसके बाद इंटरफेस पर मानव का उदाहरण दें? प्रश्न यह नहीं है कि यह कैसे काम करता है, लेकिन क्यों यह किया जाता है।
ऐसा हो सकता है, मुझे लगता है कि आप जांच के लिए 'बेसऑब्जेक्ट IInterface' करेंगे। उत्सुक है कि विधि पैरामीटर पहले से ही 'IInterface' पर टाइप नहीं किया गया है। – Jodrell