C#A中有一组数组,在B 中怎么取到数组中的值

A中有一组数组,在B 中怎么取到数组中的值

class A
{
   int[] arr=new int[10];

   public void()
     {
       for(int i=0;i<10;i++)
        {
          arr[i]=i;
        }
     }
}


class B
{
  //需要拿到A中arr的第个元素
}

如果A就这么简单的话直接用索引器就好了

    public class A
    {
        int[] arr = new int[10];
        public A()
        {
            for (int i = 0; i < 10; i++)
            {
                arr[i] = i;
            }
        }
        public int this[int index]
        {
            get
            {
                return arr[index];
            }
        }
        public int ArrLength
        {
            get { return arr.Length; }
        }
    }

    public class B
    {
        A a = new A();
        //通过索引获取
        public int GetElementFromAByIndex(int index)
        {
            if (index < 0 || index >= a.ArrLength)
            {
                throw new ArgumentOutOfRangeException("索引越界");
            }
            return a[index];
        }
        //通过序号获取
        public int GetElementFromAByOrdinal(int ordinal)
        {
            if (ordinal < 1 || ordinal > a.ArrLength)
            {
                throw new ArgumentOutOfRangeException("不正确的序号");
            }
            return a[ordinal - 1];
        }
    }

    class Program
    {
        static void Main()
        {
            B b = new B();
            //获取第一个元素
            int number1 = b.GetElementFromAByIndex(0);
            //获取最后一个元素
            int number2 = b.GetElementFromAByOrdinal(10);
        }
    }