using System;
using System.Text;
using System.Collections;namespace Test
{
class MainEntryPoint
{
static void Main()
{
MainEntryPoint m = new MainEntryPoint();
m.PrintModel<Model>(111111);
} void PrintModel<T>(int code)
where T:Model, new()
{
T modelT = new T(code); //为什么这里出错?
Console.WriteLine(modelT.Code.ToString());
}
} class Model
{
private int _code;
private string _name; public Model()
{ } public Model(int code)
{
_code = code;
} public int Code
{
get { return _code; }
set { _code = value; }
}
}}
using System.Text;
using System.Collections;namespace Test
{
class MainEntryPoint
{
static void Main()
{
MainEntryPoint m = new MainEntryPoint();
m.PrintModel<Model>(111111);
} void PrintModel<T>(int code)
where T:Model, new()
{
T modelT = new T(code); //为什么这里出错?
Console.WriteLine(modelT.Code.ToString());
}
} class Model
{
private int _code;
private string _name; public Model()
{ } public Model(int code)
{
_code = code;
} public int Code
{
get { return _code; }
set { _code = value; }
}
}}
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货