Thursday, 1 March 2012

What is Ananymous method and How to create and these are helpful?

Yes, Ananymous methods are required to simplify our task while development through tempary storage memory(method). instead of storing values into any array/ collection/ avoiding creation of type[for storing these tempary values]

Notes: at complie time complier will create an apporiate anonymous type to temparly store these values.
no need to created by  developer to overhead. so improve the performance
Ex:

 class AnonymousSample
    {
        static void Main()
        {
            AnonymousSample aobj = new AnonymousSample();
            object o = aobj.AnonysMethod();                            
        }
        public object AnonysMethod()
        {

            return new { Fname = "kasi", Lname = "babu" };
        }
        static T Cast(object obj, T type)
        {
            return (T)obj;      
        }     
    }
so these are helpful past development--->as well as-->advantage to developers.
as well as

 var objs = new { Fname = "kasi", Lname = "babu" };
            Console.WriteLine(objs.Fname);
            Console.WriteLine(objs.Lname);
            Console.ReadKey();

No comments:

Post a Comment