zoukankan      html  css  js  c++  java
  • c#学习7.索引

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;

    namespace 索引
    {
    class Program
    {
    static void Main(string[] args)
    {
    int[] values = { 3, 5, 9, 8 };
    int i = values[1];
    string s = "sss";
    s[0] = "a";
    person p1 = new person();
    p1[1] = "小明";
    Console.WriteLine(p1[1] + p1[2]);
    Console.WriteLine(p1["tome", 3, 9]);
    //为只读索引,不能赋值
    // p1["tome", 3, 9] = "111";
    Console.ReadKey();
    }
    }
    class person
    {
    private string fistname = "打毛";
    private string nextname = "xiao毛";
    public string this[string name, int a, int b]//string 索引器的数据类型,函数名是 this
    {
    get
    {
    return name + a + b;
    }
    }

    public string this[int index]
    {
    set
    {
    if (index == 1)
    {
    fistname = value;
    }
    else if (index == 2)
    {
    nextname = value;
    }
    else
    {
    throw new Exception("错误");
    }
    }
    get
    {
    if (index == 1)
    {
    return fistname;
    }
    else if (index == 2)
    {
    return nextname;
    }
    else
    {
    throw new Exception("错误");
    }

    }
    }

    }
    }

  • 相关阅读:
    [转]测试的基本概念
    记录
    flash 与 程序通讯
    怎么正确的建立项目
    安装包的制作
    JS
    页面刷新定位
    [转]C#处理XML
    MSN机器人
    报表 的使用
  • 原文地址:https://www.cnblogs.com/cyychenyijie/p/3733199.html
Copyright © 2011-2022 走看看