Main Function

namespace ConsoleGenericsAssumption
{
    class Program
    {
        static void Main(string[] args)
        {
            GenericTypeResolverTest v = new GenericTypeResolverTest("Hello Alam");
            //v.Value = "Hello ALam";
            v.ShowInConsole();
            // -----same result, differnet implementation---
            Console.WriteLine("-----same result, differnet implementation---");
            string showString = v.ToString();
            Console.WriteLine("{0}", showString);
            Console.ReadLine();

            // generic for string
            string ValueString = "Hello Yaya";
            ValueString.ShowInConsole();

            // generic for int
            int ValueInt = 12345;
            ValueInt.ShowInConsole();
        }
    }
}

 

Another class

    public class GenericTypeResolverTest
    {
        public string Value { get; set; }

        public GenericTypeResolverTest() { }
        public GenericTypeResolverTest(string value)
        {
            Value = value;
        }
        public override string ToString()
        {
            return Value.ToString();
        }
    }

    public static class GenericTypeResolverMethodTest
    {
        public static void ShowInConsole(this T obj)
        {
            Console.WriteLine(obj.ToString());
            Console.ReadLine();
        }
    }
arrow
arrow
    全站熱搜

    imagefish 發表在 痞客邦 留言(0) 人氣()