prev | next |
クラスとインスタンス - インデクサ -
// インデクサ class Program { static void Main(string[] args) { // インデクサ MyIndexer myIndexer = new MyIndexer(); Console.WriteLine(myIndexer[1]); } }
// インデクサのテスト public class MyIndexer { // インデクサの宣言 private char[] myIndex = { 'A', 'B', 'C' }; public char this[int index] { get { if (0 <= index && index < myIndex.Length) { return myIndex[index]; } return 'Z'; } set { myIndex[index] = value; } } }
prev | next |