What you want to see on DotNetFunda.com ?
DotNetFunda.Com Logo
Twitter TwitterLinkedIn
YouTubeGoogle
 Online : 1442 |  Welcome, Guest!   Register  Login
 Home > Interview Questions > ASP.NET Interview Questions > What is meant by an Indexer ? ... ...

What is meant by an Indexer ?

Interview question and answer by: Bharathi Cherukuri | Posted on: 4/26/2012 | Category: ASP.NET Interview questions | Views: 692 | | Points: 40


Answer:

An indexer is a member which enables an object to be indexed in the same way as an array.

Example:

namespace ConsoleApplication

{
using System;
class Employee
{
private string[]name = new string[10];
public string this[int index]
{
get
{
return name[index];
}
set
{
name[index] = value;
}
}
}

class Test
{
public static void Main()
{
Employee emp = new Employee();
emp[0] = "Joydip";
emp[1] = "Manashi";
emp[2] = "Jini";
Console.WriteLine("The namesare:--");
for (int i = 0; i < 3;Console.WriteLine(emp[i++]))
;
Console.ReadLine();
}
}
}


The output is as follows:

The names are:--

Joydip

Manashi

Jini

Asked In: Many Interviews | Alert Moderator 
Found interesting? Add this to:


>> Write Response - Respond to this post and get points

Even more ... | Submit Interview Questions and win prizes!

More Interview Questions from Bharathi Cherukuri

Even more ... | Submit Interview Questions and win prizes!


About Us | Contact Us | The Team | Advertise | Software Development | Write for us | Testimonials | Privacy Policy | Terms of Use | Link Exchange | Members | Go Top
General Notice: If you find plagiarised (copied) contents on this page, please let us know the original source along with your correct email id (to communicate) for further action.
Copyright © DotNetFunda.Com. All Rights Reserved. Copying or mimicking the site design and layout is prohibited. Logos, company names used here if any are only for reference purposes and they may be respective owner's right or trademarks. | 5/25/2013 7:17:54 PM