1. We have moved from vBulletin to XenForo and you are viewing the site in the middle of the move. Though the functional aspect of everything is working fine, we are still working on other changes including the new design on Xenforo.
    Dismiss Notice

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,276
    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,276
    Likes Received:
    364
    Trophy Points:
    83
    You need to get basics of Templating first.
     

Share This Page