본문 바로가기

PROGRAMMING LANGUAGE/C#

인덱서

namespace MyCshap1
{
    class MyArray
    {
        private int[] array;

        public MyArray()  
        {
            array = new int[5];
        }

        public int this[int index]
        {
            get { return array[index]; }
            set { array[index] = value; }  
        }



    }
    class Program
    {
        static void Main(string[] args)
        {
            MyArray myArray = new MyArray();
            myArray[0] = 10;
            myArray[1] = 20;
            myArray[2] = 30;
            myArray[3] = 40;
            myArray[4] = 50;

            
        }          
    }    
}

'PROGRAMMING LANGUAGE > C#' 카테고리의 다른 글

예외처리 try catch when  (0) 2022.03.02
StringBuilder  (0) 2022.02.22
string  (0) 2022.01.20
10진수, 2진수, 16진수로 변수에 값 할당하기  (0) 2022.01.19
Console 기능  (0) 2022.01.19