stackoverflow1453

Programming&&Games&&Life

Generic Methods – 1

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace _09_06_2017_a
{
    class Program
    {
        public void ReverseAndPrint<T>(T[] arr)
        {
            Array.Reverse(arr);

            foreach (var item in arr)
            {
                Console.Write("{0}", item.ToString());
            }
            Console.WriteLine(" ");
        }

        static void Main(string[] args)
        {
            var intArray = new int[] { 2, 5, 7, 3, 32, 24, 1, 5, 66, 7 };
            var stringArray = new string[] { "A", "B", "C", "D", "E", "F", "G" };
            var doubleArray = new double[] { 23, 4, 56, 7, 8 };

            Program p = new Program();

            p.ReverseAndPrint<int>(intArray);
            p.ReverseAndPrint(intArray);
            p.ReverseAndPrint<string>(stringArray);
            p.ReverseAndPrint(stringArray);
            p.ReverseAndPrint<double>(doubleArray);
            p.ReverseAndPrint(doubleArray);

            Console.ReadKey();
        }
    }
}
Advertisements

No comments yet»

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: