.net索引器
来源:互联网 发布:客户端编程 编辑:程序博客网 时间:2024/04/30 08:03
1、创建索引
private static string[] countries = new string[] { "china", "chile", "uk" }; public string this[int index] { get { return countries[index]; } } public string[] this[string name] { get { if ((countries == null) || (countries.Length <= 0)) return null; return Array.FindAll<string>(countries, delegate(string candicate) { return candicate.StartsWith(name); }); } }
2、返回索引值
SingleColumnCollection c = new SingleColumnCollection(); Console.WriteLine( c[0]);//返回索引值 Console.WriteLine( c["ch"].Length);//返回索引集合长度 Console.WriteLine( c["chi"][0]);//返回索引集合的第一个值
3、运用委托传递进行索引过滤
public class Dashboard { float[] temps = new float[10]{ 26.2F,33.5F,35.6F,39.5F,65.2F,83.5F,24.6F,86.7F,90.3F,100.5F }; public float this[Predicate<float> predicate] { get { float[] matches = Array.FindAll<float>(temps, predicate); return matches[0]; } } }
3.1调用
Dashboard dashboard = new Dashboard(); float actual = dashboard[delegate(float data) { return data > 63F; }];//返回大于63F的第一值 Console.WriteLine(actual);
0 0
- .NET 索引器
- .NET 索引器
- .net中的索引器
- .NET基础--索引器
- .net索引器
- .NET索引器
- Asp.Net中索引器的介绍
- Lucene.net索引优化
- Lucene.Net 增量索引
- lucene.net增量索引
- Lucene.Net创建索引
- .NET技术索引
- .net程序员的盲点(四):索引器Indexers
- .NET学习笔记(15)使用索引器
- .NET Expression 从零开始二:数组与对象索引器
- C#.NET常见问题(FAQ)-索引器indexer有什么用
- lucene.net 数据库全文索引
- Asp.net Mvc问题索引
- C++拷贝构造函数(深拷贝,浅拷贝)
- Linux进程模型1
- call ntdll.RtlUnicodeStringToAnsiString
- C++ cin输入流 详细用法
- 跳台阶
- .net索引器
- 变态最大值
- 计算机网络学习
- iOS之 最新苹果移动设备屏幕的大小
- JVM垃圾收集实现:垃圾收集器
- Extjs的onReady方法
- 数组 字符串遍历
- vector中v[i]和v.at(i)的区别
- 抓牛问题