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();
}
}
文章標籤
全站熱搜
