C # Indexer

Source: Internet
Author: User

Using System;namespace Indexer {class Program {static void Main (string[] args) {Phone A1 = NE            W Phone ("Xiaomi", 3000);            Console.WriteLine (A1[0]);            Console.WriteLine (A1[1]);            Console.WriteLine (A1[3]);            Console.WriteLine ("-----------------------------------------");            A1[0] = "Huawei";            A1[1] = "5000";            A1[3] = "Nokia";            Console.WriteLine (A1[0]);            Console.WriteLine (A1[1]);            Console.WriteLine (A1[3]);        Console.readkey ();        }} public class Phone {public string name;        public int price;            Public Phone (string name, int eag) {this.name = name;        This.price = EAG;                public String This[int Index] {get {if (index = = 0)                {return this.name;             } else if (index = = 1) {       Return convert.tostring (This.price);                } else {return ' cannot get an index that does not exist: ' + index; }} set {if (index = = 0) {this.name =                Value                } else if (index = = 1) {This.price = Convert.ToInt32 (value);                } else {Console.WriteLine ("Cannot set an index that does not exist:" + index); }            }        }    }}

  

C # Indexer

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.