Go4Expert

Go4Expert (http://www.go4expert.com/)
-   C# (http://www.go4expert.com/forums/c-sharp/)
-   -   Confusion :confused: (http://www.go4expert.com/forums/confusion-confused-t19670/)

ShahzadMughal 5Oct2009 16:14

Confusion :confused:
 
I couldn't understand the following code specialy underlined area

Code:

using System;

namespace overriding_method
{
    public class MyClass
    {
        public virtual void MethodA<T>(T arg)
            where T : new()
        {
        }
    }

    public class YClass : MyClass
    {
        public override void MethodA<T>(T arg)
        {
            T obj = new T();
        }
    }

    class Program
    {
        static void Main(string[] args)
        {

        }
    }
}

Thanks & Regards
Shahzad

shabbir 5Oct2009 16:27

Re: Confusion :confused:
 
Its calling the constructor

ShahzadMughal 6Oct2009 07:50

Re: Confusion :confused:
 
where T : new()
ok its calling constructor but who's?
MethodA<T>
why <T> after method name?

shabbir 6Oct2009 11:29

Re: Confusion :confused:
 
You need to get basics of Templating first.


All times are GMT +5.5. The time now is 05:55.