C#索引器 csdn上的例子
来源:互联网 发布:js判断数组不为空 编辑:程序博客网 时间:2024/06/05 19:18
class TempRecord{ // Array of temperature values private float[] temps = new float[10] { 56.2F, 56.7F, 56.5F, 56.9F, 58.8F, 61.3F, 65.9F, 62.1F, 59.2F, 57.5F }; // To enable client code to validate input // when accessing your indexer. public int Length { get { return temps.Length; } } // Indexer declaration. // If index is out of range, the temps array will throw the exception. public float this[int index] { get { return temps[index]; } set { temps[index] = value; } }}class MainClass{ static void Main() { TempRecord tempRecord = new TempRecord(); // Use the indexer's set accessor tempRecord[3] = 58.3F; tempRecord[5] = 60.1F; // Use the indexer's get accessor for (int i = 0; i < 10; i++) { System.Console.WriteLine("Element #{0} = {1}", i, tempRecord[i]); } // Keep the console window open in debug mode. System.Console.WriteLine("Press any key to exit."); System.Console.ReadKey(); }}
-----------------------------------
接口索引器
// Indexer on an interface:public interface ISomeInterface{ // Indexer declaration: int this[int index] { get; set; }}// Implementing the interface.class IndexerClass : ISomeInterface{ private int[] arr = new int[100]; public int this[int index] // indexer declaration { get { // The arr object will throw IndexOutOfRange exception. return arr[index]; } set { arr[index] = value; } }}
- C#索引器 csdn上的例子
- C# 索引器的简单例子
- C#索引器Week例子
- C#索引器week例子
- C#索引器(小例子)
- c#索引器介绍|C#索引器写法|c#索引器例子
- C#的索引器
- C#的索引器
- C#索引器-索引器的定义
- C#索引器-索引器的定义
- C#索引器-索引器的定义
- C#索引器的作用
- C#索引器的使用
- c#索引器的使用
- C#索引器的使用
- C# 索引器的使用
- C# 类的索引器
- INDEXER索引器例子
- Observer Notifications MDC
- 系统构架师学习 第六章
- RVMDK建立STM32工程
- java 一个例子
- Android_Intent和Intentfilter学习
- C#索引器 csdn上的例子
- jsp页面使用logic标签迭代list
- jqQuery常用方法
- linux-lspci
- 系统构架师学习 第七章
- Linux-iostat
- 系统构架师学习 第八章
- 系统构架师学习 第九章
- jsp页面使用logic标签迭代map