26.02.2015 Views

DOT NET Interview Questions - DotNetSpider

DOT NET Interview Questions - DotNetSpider

DOT NET Interview Questions - DotNetSpider

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

(A) What is difference between abstract classes and<br />

interfaces?<br />

Following are the differences between abstract and interfaces :-<br />

√<br />

√<br />

Abstract classes can have concrete methods while interfaces have no methods<br />

implemented.<br />

Interfaces do not come in inheriting chain , while abstract classes come in<br />

inheritance.<br />

(B) What is a delegate ?<br />

Delegate is a class that can hold a reference to a method or a function.Delegate class has<br />

a signature and it can only reference those methods whose signature is compliant with the<br />

class.Delegates are type-safe functions pointers or callbacks.<br />

Below is a sample code which shows a example of how to implement delegates.<br />

Public Class FrmDelegates<br />

Inherits System.Windows.Forms.Form<br />

Public Delegate Sub DelegateAddString()<br />

Private Sub FrmDelegates_Load(ByVal sender As System.Object,<br />

ByVal e As System.EventArgs) Handles MyBase.Load<br />

End Sub<br />

Private Sub AddString()<br />

lstDelegates.Items.Add(“Running AddString() method”)<br />

End Sub<br />

Private Sub cmdDelegates_Click(ByVal sender As System.Object,<br />

ByVal e As System.EventArgs) Handles cmdDelegates.Click<br />

Dim objDelegateAddString As DelegateAddString<br />

objDelegateAddString = AddressOf AddString<br />

objDelegateAddString.Invoke()<br />

End Sub<br />

End Class<br />

In the above there is a method called “AddString()” which adds a string to a listbox.You<br />

can also see a delegate declared as :-<br />

Public Delegate Sub DelegateAddString()<br />

This delegate signature is compatible with the “AddString” method.When i mean<br />

compatibility that means that there return types and passing parameter types are same.Later<br />

105

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!