Wednesday, 4 April 2012

GENERICS


GENERICS EXAMPLE 1

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

namespace ConsoleApplication15
{
    class Program
    {
        public static void DisplayArray(T[] array)
        {
            foreach (T item in array)
            {
                Console.WriteLine("{0}",item);
            }
        }
        static void Main(string[] args)
        {
            string[] myFriends = { "vijay","raj","sunil"};
            int[] mm = {1,2,3};
            //Program p = new Program();
            //invoke generic method and specify type parameter implicitily
            Program.DisplayArray(myFriends);
            Program.DisplayArray(mm);
            //invoke generic method and specify type parameter implicitily
            //p.DisplayArray(myFriends);
            //p.DisplayArray(mm);
        }
    }
}


GENERICS EXAMPLE 2

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

namespace ConsoleApplication16
{
    class Program
    {
        public static void display(T s)
        {
            Console.WriteLine("value is:-"+s);
        }
        static void Main(string[] args)
        {
            display(12);
            display("vijay");
            display(19.6);
        }
    }
}

No comments:

Post a Comment

CRUD operations using AngularJS in Asp.Net MVC

In this article I will show you how to perform CRUD operations in Asp.Net MVC5 using AngularJS. Add AngularJS using the Manage Nuget Pack...