Calling VB.NET Property marked as 'Default' in C# code



Few months back I have a create a dll in VB.NET and I was referencing this DLL in my C# application (asp.net). The problem which I was facing that there was a property in the VB.net code which was marked as Default and in C# there is no such keywords. The property was something like :


Default Public Overloads ReadOnly Property GetEmployeeSalary(ByVal EmpId As Int64) As Int64
Get '' calculate and return some value End Get
End Property
In VB.NET we just create a instance of the class and pass the parameter to the instance of the class like


Dim obj As New ClassName
Dim result As Int64= obj(12345);
But I was not able to find a way in the C# to call this property. I have searched a lot on the net and posted my questions in many forums then I got the answer and then I thought I should share it with you people also. Basically in C# we use Indexers which is equivalent to the default properties in the VB.NET. So I called the VB.NET default property in the C# code as follows:

ClassName obj = new ClassName();
Int64 result = obj[12345];
Happy coding .!!!!!!!

Comments