关于《Programming .Net Components》第六章 的一个疑问

tyzyx 2008-07-03 05:24:18
本章 示例 6-10(EventsHelper)后 与 6-12(事件访问器) 代码中提到以下形式定义,
using MyEventHandler = GenericEventHandler<int, string>;
请问,6-12为何无法编译通过?缺少代码(public delegate void GenericEventHandler<T, U>(T t, U u) ;)?
这种用法谁能帮忙更加详细的讲解一下。
...全文
104 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
kookboo 2009-04-15
  • 打赏
  • 举报
回复
look一下,还没看到这个地方
bb78bob 2008-10-24
  • 打赏
  • 举报
回复
找到这个帖子真不容易。
using 泛型 类型别名
fuadam 2008-07-07
  • 打赏
  • 举报
回复
using语句必须放到命名空间外面去,这样改就ok了

using MyEventHandler = GenericEventHandler<int, string>;
public delegate void GenericEventHandler<T, U>(T t, U u);

namespace WindowsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
}
}
tyzyx 2008-07-07
  • 打赏
  • 举报
回复
代码如下,编译错误为

error CS1529: A using clause must precede all other namespace elements except extern alias declarations


using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace WindowsApplication1
{
public delegate void GenericEventHandler<T, U>(T t, U u);
using MyEventHandler = GenericEventHandler<int, string>;
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
}
}
一品梅 2008-07-03
  • 打赏
  • 举报
回复
不懂,帮顶.
fuadam 2008-07-03
  • 打赏
  • 举报
回复
这个的using就是起别名用的,比如
using mystring = System.String; 你就可以用 mystring s = "abc";

所以你要有public delegate void GenericEventHandler <T, U>(T t, U u) ;的定义才能 使用using 语法给GenericEventHandler <int, string>其别名

给个例子: using myfunc = System.Predicate<int>;

110,538

社区成员

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

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

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