以下代码为何编译不过,帮看看

liumang9527 2008-05-02 12:11:45
以下代码为何编译不过,我用的是VC2003.NET



using System;
using System.Collections.Generic;
using System.Text;

namespace Huaquan
{

/// <summary>
/// 酒鬼类
/// </summary>
public abstract class Drunkard
{
abstract public void Come(out int AFinger, out int ASum);

abstract public void Outcome(int AOtherFinger, int AOtherSum, Result AOtherResult,
int ASelfFinger, int ASelfSum, Result ASelfResult);
}

public class Zswang一号 : Drunkard
{
public override void Come(out int AFinger, out int ASum)
{
AFinger = 5; // 每次都出5
ASum = 10; // 每次都猜10
}

public override void Outcome(int AOtherFinger, int AOtherSum, Result AOtherResult,
int ASelfFinger, int ASelfSum, Result ASelfResult)
{
/* 这机器人不关心比赛结果 */
}
}

public class Zswang二号 : Drunkard
{
private Random random;
public Zswang二号()
{
random = new Random();
}

public override void Come(out int AFinger, out int ASum)
{
ASum = random.Next(10 + 1); //0-10
if (ASum < 5) // 别犯规
AFinger = random.Next(ASum + 1);
else AFinger = random.Next(ASum - 5, 5 + 1);
}

public override void Outcome(int AOtherFinger, int AOtherSum, Result AOtherResult,
int ASelfFinger, int ASelfSum, Result ASelfResult)
{
/* 这机器人也不关心比赛结果 */
}
}

/// <summary>
/// 酒馆类
/// </summary>
/// <typeparam name="T1">划拳机器人1</typeparam>
/// <typeparam name="T2">划拳机器人2</typeparam>
public class Drunkery<T1, T2>
where T1 : Drunkard, new()
where T2 : Drunkard, new()
{
public void Play()
{
;
}
}

class Program
{
static void Main(string[] args)
{
new Drunkery<Zswang一号, Zswang二号>().Play();
}
}
}


------ 已启动生成: 项目: ProjectTest, 配置: Debug .NET ------

正在准备资源...
正在更新引用...
正在执行主编译...
d:\workspace\projecttest\codefile1.cs(77,23): error CS1514: 应输入 {
d:\workspace\projecttest\codefile1.cs(77,26): error CS1519: 类、结构或接口成员声明中的标记“,”无效
d:\workspace\projecttest\codefile1.cs(77,30): error CS1519: 类、结构或接口成员声明中的标记“>”无效
d:\workspace\projecttest\codefile1.cs(78,12): error CS1002: 应输入 ;
d:\workspace\projecttest\codefile1.cs(78,22): error CS1519: 类、结构或接口成员声明中的标记“,”无效
d:\workspace\projecttest\codefile1.cs(78,27): error CS1031: 应输入类型
d:\workspace\projecttest\codefile1.cs(79,12): error CS1002: 应输入 ;
d:\workspace\projecttest\codefile1.cs(79,22): error CS1519: 类、结构或接口成员声明中的标记“,”无效
d:\workspace\projecttest\codefile1.cs(79,27): error CS1031: 应输入类型

生成完成 -- 9 个错误,0 个警告
正在生成附属程序集...
由于缺少主项目输出,未能生成附属程序集。


---------------------- 完成 ---------------------

生成: 0 已成功, 1 已失败, 0 已跳过


...全文
117 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
ju_feng 2008-05-02
  • 打赏
  • 举报
回复
对,需要在VS2005以后的版本才能编译过

或者去掉/// <summary>
/// 酒馆类
/// </summary>
/// <typeparam name="T1">划拳机器人1</typeparam>
/// <typeparam name="T2">划拳机器人2</typeparam>
public class Drunkery<T1, T2>
where T1 : Drunkard, new()
where T2 : Drunkard, new()
{
public void Play()
{
;
}
}
occam 2008-05-02
  • 打赏
  • 举报
回复
.net 1.1及之前版本没有泛型的说..
liumang9527 2008-05-02
  • 打赏
  • 举报
回复
感谢楼上各位

以上代码能做修改使之在VS2003版本运行吗?

changjiangzhibin 2008-05-02
  • 打赏
  • 举报
回复

//由于泛型属于VS2005对应VS2003的新特性,须在VS2005中方可运行通过
public class Drunkery<T1, T2>
where T1 : Drunkard, new()
where T2 : Drunkard, new()
{
public void Play()
{
;
}
}
xeonfeng 2008-05-02
  • 打赏
  • 举报
回复
楼主需要参考MSDN的泛型
wudi626 2008-05-02
  • 打赏
  • 举报
回复
[Quote=引用 9 楼 goga21cn 的回复:]
改2.0吧
[/Quote]
龙宜坡 2008-05-02
  • 打赏
  • 举报
回复
改2.0吧
onthebox 2008-05-02
  • 打赏
  • 举报
回复
早先的只有ArrayList
先以object类型放在ArrayList中
需要的时候在强制转换
Kevin_LiuFeng 2008-05-02
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 ju_feng 的回复:]
对,需要在VS2005以后的版本才能编译过

或者去掉/// <summary>
/// 酒馆类
/// </summary>
/// <typeparam name="T1">划拳机器人1 </typeparam>
/// <typeparam name="T2">划拳机器人2 </typeparam>
public class Drunkery <T1, T2>
where T1 : Drunkard, new()
where T2 : Drunkard, new()
{
public void Play()
{
;

[/Quote]

110,538

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧