Introduction:
In this article i am going to explain about how to use c# function pointer delegates and interfaces in windows forms.
Main:
Before stating this article,we must know what is delegates?
Delegates are function pointers,
Delegates are type-safe and object oriented,
Delegates hold references of one or more functions and invoke them as needed,
Delegates are dynamic and are declared at runtime,
Delegates can point a set of ordered functions,
for ex,
Delegate void sampledelegate (string a);
class DelegateClass
{
public void Welcome(string a)
{
return "This is delegates sample"
}
}
Delegate void sampledelegate (string a); class DelegateClass { public void Welcome(string a) { return "This is delegates sample" } } |
Delegate instance encaptulates more than one method,and each of these is called callable entity,
sampledelegate delobj = new sampledelegate (DelegateClass.Welcome)
Interfaces:
Simply we can define interface as “Contract”.What are the classes and structs defined interfaces
are simply signed some contracts.
what is a contract? An interface contract is a guarantee by an object that it will support all of
the elements of its interface. This contract is created using the Interface keyword, which declares
a reference type that encapsulates the contract.
An interface can the following as members,
Events,Indexers,Methods,Properties,
Interface IsampleInterface
{
void Calculatevalue ()
}
Interface IsampleInterface { void Calculatevalue () } |
all methods,events,properties are declared inside interfaces are considered as public,
For calling interface just inherit it,
class Implementer : IsampleInterface
Conclusion:
Hope this helps,
Happy Coding.
Hi, just needed you to know I have added your site to my Google bookmarks because of your extraordinary blog layout. But seriously, I think your site has one of the freshest theme I’ve came across. It really helps make reading your blog a lot easier.