C # Indexer Implementation process

Source: Internet
Author: User

Each attribute of a class must have a unique name, and each indexer defined in the class must have a unique signature

Or a list of arguments so that you can implement the index reset. The property can be static, and the indexer must be an instance member. For cable

The access function defined by the primer can access the arguments passed to the indexer, and the property access function has no parameters. We can also

Port definition Indexer, when declaring an indexer for an interface, remember that the declaration simply represents the presence of the indexer, and you only need to provide a

You do not have to include modifiers when you access a function.

Look at the following case:

ITestIndex.cs file

Using System;
Using System.Collections.Generic;
Using System.Linq;
Using System.Text;

Namespace Algorithmdemo
{
    interface itestindex
    {
        string This[int index]
        {get
            ;
            Set;}}}

TestIndex.cs file

Using System;
Using System.Collections.Generic;
Using System.Linq;
Using System.Text;

Namespace Algorithmdemo
{
    class testindex<t>
    {
        private t[] arr = new t[100];
        Public T This[int i]
        {get
            {return arr[i];}
            set {Arr[i] = value;}}}

Program.cs

Using System;
Using System.Collections.Generic;
Using System.Linq;
Using System.Text;

Namespace Algorithmdemo
{
    class program
    {
        static void Main (string[] args)
        {

            testindex< string> test = new testindex<string> ();
            String data = "hello,world!";

            for (int i = 0; i < data. Length; i++)
            {
                Test[i] = data[i]. ToString ();
            }

            for (int i = 0; i < data. Length; i++)
            {
                console.write (test[i]);
            }
            while (true);}}
   
          
Effect Chart:






















Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.