zoukankan      html  css  js  c++  java
  • C#中的索引器

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

    namespace ConsoleApplication2
    {
        class Program
        {
            public static void Main(string[] args)
            {
                Student[] stu = new Student[3];
                stu[0] = new Student("张三",23);
                stu[1] = new Student("李四",34);
                Stus stus = new Stus();
                stus.students = stu;
                Console.WriteLine(stus[1].age);
            }              
        }


        public class Student
        {
            public string name;
            public int age;
            public Student(string name, int age)
            {
                this.name = name;
                this.age = age;
            }
        }

        public class Stus
        {
            public Student[] students;
            public Student this[int index]
            {
                get
                {
                    return students[index];
                }
            }
            public Student this[string name]
            {
                get
                {
                    for (int i = 0; i < students.Length; i++)
                    {
                        if (students[i].name == name)
                        {
                            return students[i];
                        }
                    }
                    return null;
                }
            }
        }

    }

  • 相关阅读:
    Pythonlistsort()
    [转]Python中文乱码问题深入分析
    使用dom4j时SelectNodes()方法报错
    Xpath语法
    wust2012级软件工程新生经验交流会草稿
    Eclipse中部分快捷键
    Dom4j解析XML学习代码
    html5 cocos2d
    mfc mfc100ud.dll丢失问题
    c# 类操作 窗体
  • 原文地址:https://www.cnblogs.com/tianguook/p/1795997.html
Copyright © 2011-2022 走看看