欢迎光临极品网,更多、更新的资源信息尽在Jpinw.Com!本站所有信息资源每日更新新的内容,请大家继续关注www.Jpinw.com!如果觉得本站还不错,对您有帮助,别忘了向您的朋友推荐本站!请记好本站网址:http://www.Jpinw.com,网站发展靠大家多多的支持!!!

极品网 极品课件 极品论文 极品文学 极品游戏 极品美容 极品手机资源 极品股票

#
免费资源: 免费域名 | 免费空间 | 免费推广 | 免费邮箱 | 免费硬盘 | 免费论坛 | 免费留言 | 免费统计 | 在线投稿 | 更多...
电脑学院: 操作系统 | 安全相关 | 网页设计 | 编程开发 | 建站经验 | 服务器类 | 黑客攻防 | 菜鸟入门 | 教你网赚 | 更多...
文章导航: 网赚学堂 | 网赚秘笈 | 网赚三维 | 网赚先锋 | 网赚资讯 | 感悟网赚 | 众生百态 | 经典美文 | 范文中心 | 更多...
图酷天下: 时事图酷 | 娱乐图酷 | 搞笑图酷 | 时尚图酷 | 体育图酷 | 另类经典 | 论文资源 | 课件下载 | 文学知识 | 更多...

您现在的位置: 极品网 >> 电脑学院 >> 编程开发 >> C#VBJAVA >> 教程正文

c#v2.0 扩展特性 翻译(1)            【字体:
c#v2.0 扩展特性 翻译(1)
作者:佚名    教程来源:不详    点击数:    更新时间:2008-6-4    

 








c#v2.0 扩展特性 翻译(1)。
  Introduction to C# 2.0
C# 2.0 introduces several language extensions, the most important of which are Generics, Anonymous Methods, Iterators, and Partial Types.

C#2.0 介绍几种语言扩展,泛型,匿名方法,迭代器 和、partial Types.

· Generics permit classes, structs, interfaces, delegates, and methods to be parameterized by the types of data they store and manipulate. Generics are useful because they provide stronger compile-time type checking, require fewer explicit conversions between data types, and reduce the need for boxing operations and run-time type checks.

泛型允许类,结构,接口,代理还有方法被他们存储和操作数据类型参数化。泛型相当有用,因为他们提供强制的编译时类型检查,要求更少的数据类型之间的显式转换,并减少装箱拆箱的操作和运行时类型检查。

· Anonymous methods allow code blocks to be written “in-line” where delegate values are expected. Anonymous methods are similar to lambda functions in the Lisp programming language. C# 2.0 supports the creation of “closures” where anonymous methods access surrounding local variables and parameters.

· Iterators are methods that incrementally compute and yield a sequence of values. Iterators make it easy for a type to specify how the foreach statement will iterate over its elements.

· Partial types allow classes, structs, and interfaces to be broken into multiple pieces stored in different source files for easier development and maintenance. Additionally, partial types allow separation of machine-generated and user-written parts of types so that it is easier to augment code generated by a tool.

This chapter gives an introduction to these new features. Following the introduction are four chapters that provide a complete technical specification of the features.

这个章节将介绍这些新特性。随后的四个章节的介绍将提供有关特性的完整技术规范

The language extensions in C# 2.0 were designed to ensure maximum compatibility with existing code. For example, even though C# 2.0 gives special meaning to the words where, yield, and partial in certain contexts, these words can still be used as identifiers. Indeed, C# 2.0 adds no new keywords as such keywords could conflict with identifiers in existing code.

c#2.0中的语言扩展最大程度上保证和现有代码的兼容。举例说,即使c#2.0指定以下词如yield,partial在特定的上下文有特有的意义,他们依然可以作为标示符。甚至,c#2.0没有加任何新的可能会在现有代码冲突的关键词

Generics
Generics permit classes, structs, interfaces, delegates, and methods to be parameterized by the types of data they store and manipulate. C# generics will be immediately familiar to users of generics in Eiffel or Ada, or to users of C++ templates, though they do not suffer many of the complications of the latter.

泛型允许类,结构,接口,代理和方法被他们存储操作的数据类型参数化。C#泛型将很快被eiffel,ada的使用过泛型的用户熟悉,或是使用过c++templates,尽管他们不需要忍受以后的多种编译器。



Why generics?
Without generics, general purpose data structures can use type object to store data of any type. For example, the following simple Stack class stores its data in an object array, and its two methods, Push and Pop, use object to accept and return data, respectively:

如果没有泛型,一般数据结构能使用类型对象去存储任何数据类型。举例,下面所描述的一个很简单的栈的类存储数据在对象数组中。它有两个方法push和pop,使用对象分别地去接受和返回数据

public class Stack
{
object[] items;
int count;

public void Push(object item) {...}

public object Pop() {...}
}

While the use of type object makes the Stack class very flexible, it is not without drawbacks. For example, it is possible to push a value of any type, such a Customer instance, onto a stack. However, when a value is retrieved, the result of the Pop method must explicitly be cast back to the appropriate type, which is tedious to write and carries a performance penalty for run-time type checking:

当使用对象类型的时候栈类的使用更灵活,它并非没有缺陷。举例说,它很可能压入任何类型的值,如一个customer实例到一个栈。然而,当一个值返回,pop方法返回的

[1] [2] 下一篇

 

教程录入:admin    责任编辑:admin 
  • 上一篇教程:

  • 下一篇教程:
  • 发表评论】【加入收藏】【告诉好友】【打印此文】【关闭窗口
    最新热点 最新推荐 相关教程
    C#:Web Service异常处理
    C#:获得文件版本信息及只读文
    C#:文件的按行读/写及文件目
    C#2.0 Specification(泛型二
    C#2.0 Specification(泛型一
    C#2.0 新特性探究(二) 委托与
    C#2.0的特性
    C#2.0简介
    C#2.0语言规范(三)匿名方法
    C#2.0语言规范(四)迭代器
      网友评论:(只显示最新10条。评论内容只代表网友观点,与本站立场无关!)
    极品网
    | 设为首页 | 加入收藏 | 友情链接 | 版权声明 |
    极品网

    Copyright 2006 Jpinw.com 极品网

    备案号:浙ICP备07010375号

    极品网