Exemplo n.º 1
0
        static void Main(string[] args)
        {
            var first = new WrappedArray(4, 8, 6);

            Console.WriteLine(first);
            first.Add(7, 8, 9);
            Console.WriteLine(first);
            Console.WriteLine("Contains 7: {0}", first.Contains(7));
            Console.WriteLine("Get by index 1: {0}", first.GetByIndex(1));
            var second = new WrappedArray(7, 5, 3, 8, 6, 1);

            Console.WriteLine(second);
            Console.WriteLine("Contains 9: {0}", second.Contains(9));
            Console.WriteLine("Get by index 4: {0}", second.GetByIndex(4));
            Console.ReadLine();
        }
Exemplo n.º 2
0
        static void Main(string[] args)
        {
            var first = new WrappedArray(1, 2, 3);

            Console.WriteLine(first);
            Console.WriteLine("Contains 4: {0}", first.Contains(4));
            try
            {
                Console.WriteLine("Getting by index 4: {0}", first.GetByIndex(4));
            }
            catch (IndexOutOfRangeException ex)
            {
                Console.WriteLine(ex.Message);
            }

            first.Add(4, 5);
            Console.WriteLine(first);
            Console.WriteLine("Contains 4: {0}", first.Contains(4));
            Console.WriteLine("Getting by index 4: {0}", first.GetByIndex(4));

            var second = new WrappedArray(new int[] { 3, 4, 5, 6, 2 });

            Console.WriteLine(second);
            Console.WriteLine("Contains 0: {0}", second.Contains(0));
            try
            {
                Console.WriteLine("Getting by index -1: {0}", second.GetByIndex(-1));
            }
            catch (IndexOutOfRangeException ex)
            {
                Console.WriteLine(ex.Message);
            }

            second.Add(new int[] { 15, 6, 0, 32, 46, 12, 3, 4, 5, 9, 0, 0, 0, 7 });
            Console.WriteLine(second);
            Console.WriteLine("Contains 0: {0}", second.Contains(0));
            Console.WriteLine("Getting by index 2: {0}", second.GetByIndex(2));

            Console.ReadLine();
        }
Exemplo n.º 3
0
        // System.Array.FindIndex(T[], int, int, Predicate)

        public static int FindIndex <T>(T[] arr, int i, int n, Func <T, bool> p)
        {
            int j = new WrappedArray <T>(arr).View(i, n).FindIndex(p);

            return(j < 0 ? j : j + i);
        }
Exemplo n.º 4
0
        // System.Array.LastIndexOf(T[], T, int, int)

        public static int LastIndexOf <T>(T[] arr, T x, int i, int n)
        {
            int j = new WrappedArray <T>(arr).View(i, n).LastIndexOf(x);

            return(j < 0 ? -1 : j + i);
        }
Exemplo n.º 5
0
        // System.Array.LastIndexOf(T[], T)

        public static int LastIndexOf <T>(T[] arr, T x)
        {
            int j = new WrappedArray <T>(arr).LastIndexOf(x);

            return(j < 0 ? -1 : j);
        }
Exemplo n.º 6
0
        // System.Array.IndexOf(T[], T, int)

        public static int IndexOf <T>(T[] arr, T x, int i)
        {
            int j = new WrappedArray <T>(arr).View(i, arr.Length - i).IndexOf(x);

            return(j < 0 ? -1 : j + i);
        }
Exemplo n.º 7
0
        // System.Array.FindLastIndex(T[], int, Predicate)

        public static int FindLastIndex <T>(T[] arr, int i, Fun <T, bool> p)
        {
            int j = new WrappedArray <T>(arr).View(i, arr.Length - i).FindIndex(p);

            return(j < 0 ? j : j + i);
        }