1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Confusion :confused:

Discussion in 'C#' started by ShahzadMughal, Oct 5, 2009.

  1. ShahzadMughal

    ShahzadMughal New Member

    Joined:
    Nov 7, 2008
    Messages:
    9
    Likes Received:
    0
    Trophy Points:
    0
    I couldn't understand the following code specialy underlined area

    Code:
    using System;
    
    namespace overriding_method
    {
        public class MyClass
        {
            public virtual void MethodA[U]<T>[/U](T arg)
                [U]where T : new()[/U]
            {
            }
        }
    
        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
     
  2. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,285
    Likes Received:
    364
    Trophy Points:
    83
    Its calling the constructor
     
  3. ShahzadMughal

    ShahzadMughal New Member

    Joined:
    Nov 7, 2008
    Messages:
    9
    Likes Received:
    0
    Trophy Points:
    0
    where T : new()
    ok its calling constructor but who's?
    MethodA<T>
    why <T> after method name?
     
  4. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,285
    Likes Received:
    364
    Trophy Points:
    83
    You need to get basics of Templating first.
     

Share This Page