Click here to Skip to main content
15,893,381 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more:
Hi,

I am a begginner. Can anyone please tell me the proper definition and use of indexers in C# with a good example?
Posted
Updated 15-Nov-10 23:49pm
v2

private void button1_Click(object sender, RoutedEventArgs e)
    {
        Students obj = new Students();
        string FirstName = obj[0];//Getting Item using Indexers
        obj[2] = "Tim";//Modifying Item using Indexers
    }
    public class Students
    {
        List<string> students = new List<string>() { "Eric", "Bill", "Joseph" };
        public string this[int ind]
        {
            get { return students[ind]; }
            set { students[ind] = value; }
        }
    }
 
Share this answer
 
Comments
Abhinav S 16-Nov-10 6:29am    
Good anser. 5.
This[^] should be a good link for you.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900