一代軍師
程式語言、理財自我投資、加密貨幣、資訊安全 https://moushih.com/
public class CommonMethod
{
/// <summary>
/// 印出int數值
/// </summary>
/// <param name="iParameter"></param>
public static void ShowInt(int iParameter)
{
Console.WriteLine("This is {0},parameter={1},type={2}",
typeof(CommonMethod).Name, iParameter.GetType().Name, iParameter);
}
/// <summary>
/// 印出string數值
/// </summary>
/// <param name="iParameter"></param>
public static void ShowString(string iParameter)
{
Console.WriteLine("This is {0},parameter={1},type={2}",
typeof(CommonMethod).Name, iParameter.GetType().Name, iParameter);
}
/// <summary>
/// 印出DateTime數值
/// </summary>
/// <param name="iParameter"></param>
public static void ShowDateTime(DateTime iParameter)
{
Console.WriteLine("This is {0},parameter={1},type={2}",
typeof(CommonMethod).Name, iParameter.GetType().Name, iParameter);
}
}
static void Main(string[] args)
{
int iValue = 123;
string sValue = "123";
DateTime dtValue = DateTime.Now;
CommonMethod.ShowInt(iValue);
CommonMethod.ShowString(sValue);
CommonMethod.ShowDateTime(dtValue);
}
public class GenericMethod
{
public static void Show<myName>(myName tParameter)
{
Console.WriteLine("This is {0},parameter={1},type={2}",
typeof(GenericMethod),tParameter.GetType().Name,tParameter.ToString());
}
}
void Main()
{
try
{
int iValue = 123;
string sValue = "456";
DateTime dtValue = DateTime.Now;
GenericMethod.Show<int>(iValue);
GenericMethod.Show<string>(sValue);
GenericMethod.Show<DateTime>(dtValue);
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
}