C# 索引器
来源:互联网 发布:c 并发编程 编辑:程序博客网 时间:2024/05/29 04:15
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 name = new IndexedName(); name[0] = "1"; name[1] = "2"; name[2] = "3"; name[3] = "4"; name[4] = "5"; name[5] = "6"; name[6] = "7"; name[7] = "8"; name[8] = "9"; name[9] = "10"; for (int i = 0; i <= 10; i++) { Console.WriteLine(name[i]); } Console.WriteLine(name["10"]); Console.WriteLine(name["fweggreg"]); Console.ReadKey(); } } //在类上实现索引器 class IndexedName { string[] nameList = new string[10]; public IndexedName() { for (int i = 0; i < nameList.Length - 1; i++) { nameList[i] = "N/A"; } } public string this[int index] { get { if (index >= 0 && index <= nameList.Length - 1) { return nameList[index]; } return "Error!"; } set { if (index >= 0 && index <= nameList.Length - 1) { nameList[index] = value; } } } public int this[string name] { get { int index = 0; while (index < nameList.Length) { if (nameList[index] == name) { return index; } index++; } return -1; } } } //在接口上建立索引器 public interface ISomeInterface { int this[int inedx] { get; set; } } class IndexerClass : ISomeInterface { private int[] arr = new int[100]; public int this[int index] { get { return arr[index]; } private set { arr[index] = value; } } }}
0 0
- C#索引器
- C#索引器
- C#索引器
- C#中的索引器
- C#索引器
- C# 索引器
- C#索引器
- C#索引器
- C# 索引器
- C#索引器
- C#索引器
- C#索引器
- C#索引器
- c#属性 索引器
- C#的索引器
- C#索引器
- C#索引器
- C#索引器
- rownum与ORDER BY疑问 rownum不支持order by 排序 先排序再rownum的方法
- scrollWidth,clientWidth,offsetWidth的区别
- 接口的应用-制定标准
- centos64 mysql socket问题
- spring mvc与Mybatis整合——(三)增删改查
- C# 索引器
- 第一章:Spring Web MVC入门——深入浅出学Spring Web MVC
- lightoj 1269(trie)
- 商城秒杀倒计时
- android输入法操控-关闭开启...
- 在GridView中添加按钮后,如何触发按钮的各种事件?
- 栈----实则运算表达式求值(2)
- ffmpeg reference
- 截取最后一个"\"的字符串