C#索引器重写

本篇将介绍如何使用C#来重写索引器。 如果,你对C#索引器不是很了解,可以通过查看本站文章: 如何用C#来构造一个索引器 根据上一篇的基础,我们来重写一个索引器,这次我们通过名称来查看数组的位置: public int this[string name] { get { int index = 0; while (index < NameList.Length) { if (NameList[index]==name) { return index;…

如何用C#来构造一个索引器

本篇将介绍如何通过C#来构造一个索引器(Indexer) 这里使用的方法是通过创建一个类,将构造函数写成创建一个数组。 然后通过get和set函数来实现内容的读写。 using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threading.Tasks;namespace Indexer{ class Program { static void Main(string[] args) { var names = new IndexNames(); names[0] =…