版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、C# 语法表现力强, 而且简单易学。 C# 的大括号语法使任何熟悉 C、C+ 或 Java 的人都可以立即上手。 了解上述任何一种语言的开发人员通常在很短的时 间内就可以开始使用 C# 高效地进行工作。 C# 语法简化了 C+ 的诸多复杂 性,并提供了很多强大的功能, 例如可为 null 的值类型、 枚举、委托、 lambda 表达式和直接内存访问,这些都是 Java 所不具备的。 C# 支持泛型方法和类 型,从而提供了更出色的类型平安和性能。 C# 还提供了迭代器, 允许集合类的 实施者定义自定义的迭代行为,以便容易被客户端代码使用。在 C# 3.0 中, 语言集成查询 (LINQ) 表达式
2、使强类型查询成为了一流的语言构造。作为一种面向对象的语言, C# 支持封装、 继承和多态性的概念。 所有的变量和 方法,包括 Main 方法应用程序的入口点,都封装在类定义中。类可能直 接从一个父类继承, 但它可以实现任意数量的接口。 重写父类中的虚方法的各种 方法要求 override 关键字作为一种防止意外重定义的方式。在 C# 中,结 构类似于一个轻量类; 它是一种堆栈分配的类型, 可以实现接口, 但不支持继承。除了这些根本的面向对象的原理之外, C# 还通过几种创新的语言构造简化了软 件组件的开发,这些结构包括:? 封装的方法签名称为 “委托 ,它实现了类型平安的事件通知。? 属性 (
3、Property) ,充当私有成员变量的访问器。? 属性 (Attribute) ,提供关于运行时类型的声明性元数据。? 内联 XML 文档注释。? 语言集成查询 (LINQ) ,提供了跨各种数据源的内置查询功能。在 C# 中,如果必须与其他 Windows 软件如 COM 对象或本机 Win32 DLL 交互,那么可以通过一个称为 “互操作 的过程来实现。互操作使 C# 程序 能够完本钱机 C+ 应用程序可以完成的几乎任何任务。在直接内存访问必不 可少的情况下, C# 甚至支持指针和 “不平安 代码的概念。C# 的生成过程比 C 和 C+ 简单,比 Java 更为灵活。没有单独的头文件, 也
4、不要求按照特定顺序声明方法和类型。 C# 源文件可以定义任意数量的类、 结 构、接口和事件。以下各项是其他 C# 资源:?有关C#语言特定方面的详细信息,请参见 C#参考?有关C#语法与Java和C+语法的比较,请参见C#编程语言针对Java开发人员和C#针对C+开发人员。?有关LINQ的更多信息,请参见语言集成查询(LINQ)。?假设要查找Visual C# 团队提供的最新文章和资源,请访冋Visual C# 开发中心。.NET Framework平台体系结构C# 程序在.NET Framework 上运行,它是 Windows 的个不可或缺的组 件,包括一个称为公共语言运行库(CLR)的虚
5、拟执行系统和一组统一的类库。CLR是Microsoft的公共语言根底结构(CLI)的商业实现。CLI是一种国际 标准,是用于创立语言和库在其中无缝协同工作的执行和开发环境的根底。用C#编写的源代码被编译为一种符合CLI标准的中间语言(IL) IL代码与资源例如位图和字符串一起作为一种称为程序集的可执行文件存储在磁盘上, 通常具有的扩展名为.exe或.dll。程序集包含清单,它提供有关程序集的类 型、版本、区域性和平安要求等信息。执行C#程序时,程序集将加载到 CLR中,这可能会根据清单中的信息执行 不同的操作。然后,如果符合平安要求,CLR就会执行实时(JIT)编译以将IL 代码转换为本机机器
6、指令。CLR还提供与自动垃圾回收、异常处理和资源管理 有关的其他效劳。由CLR执行的代码有时称为 托管代码它与编译为面向特 定系统的本机机器语言的 非托管代码相对应。以以下图阐释了 C#源代码文 件、.NET Framework类库、程序集和CLR的编译时与运行时的关系。1rvisual C*直目K?!: i.ewe 遊.dllHSIL 尤蜀掘CLR llUltPJ IL元汝氐杠引用-NET Framevrork i,舍丁:治“企时奴Q#拉妙州/JIT.MET Frmwrk啊撫为本Flit 1T机优科语言互操作性是.NET Framework的一项主要功能。因为由C#编译器生成的IL代码符合公
7、共类型标准CTS,因此从C#生成的IL代码可以与从Visual Basic、Visual C+、Visual J# 的.NET 版本或者其他 20 多种符合CTS的语言中的任何一种生成的代码进行交互。单一程序集可能包含用不 同.NET语言编写的多个模块,并且类型可以相互引用,就像它们是用同一种 语言编写的。除了运行时效劳之外,.NET Framework还包含一个由4000多个类组成的内容详尽的库,这些类被组织为命名空间,为从文件输入和输出、字符串操作、 XML分析到Windows窗体控件的所有内容提供了各种有用的功能。典型的 C#应用程序使用.NET Framework类库广泛地处理常见的
8、日常任务。C# syntax is highly expressive, yet it is also simple and easy to learn. The curly-brace syntax of C# will be instantly recognizable to anyone familiar with C, C+ or Java. Developers who know any of these languages are typically able to begin to work productively in C# within a very short time.
9、 C# syntax simplifies many of the complexities of C+ and provides powerful features such as nullable value types, enumerations, delegates, lambda expressions and direct memory access, which are not found in Java. C# supports generic methods and types, which provide increased type safety and performa
10、nce, and iterators, which enable implementers of collection classes to define custom iteration behaviors that are simple to use by client code. In C# 3.0, Language-Integrated Query (LINQ) expressions make the strongly-typed query a first-class language construct.As an object-oriented language, C# su
11、pports the concepts of encapsulation, inheritance, and polymorphism. All variables and methods, including theMain method, the applications entry point,are encapsulated within class definitions. A class may inherit directly from one parent class, but it may implement any number of interfaces. Methods
12、 that override virtual methods in a parent class require the override keyword as a way to avoid accidental redefinition. In C#, a struct is like a lightweight class; it is a stack-allocated type that can implement interfaces but does not support inheritance.In addition to these basic object-oriented
13、 principles, C# makes it easy to develop software components through several innovative language constructs, including the following:? Encapsulated method signatures called delegates , which enable type-safe event notifications.? Properties, which serve as accessors for private member variables.? At
14、tributes, which provide declarative metadata about types at run time.? Inline XML documentation comments.? Language-Integrated Query (LINQ) which provides built-in query capabilities across a variety of data sources.If you have to interact with other Windows software such as COM objects or native Wi
15、n32 DLLs, you can do this in C# through a process called Interop. Interop enables C# programs to do almost anything that a native C+ application can do. C# even supports pointers and the concept of unsafe code for those cases in which direct memory access is absolutely critical.The C# build process
16、is simple compared to C and C+ and more flexible than in Java. There are no separate header files, and no requirement that methods and types be declared in a particular order. A C# source file may define any number of classes, structs, interfaces, and events.The following are additional C# resources
17、:? For a good general introduction to the language, see Chapter 1 of the C# Language Specification.? For detailed information about specific aspects of the C# language, see the C# Reference.? For a comparison of C# syntax to Java and C+, see The C# Programming Language for Java Developers and C# for
18、 C+ Developers.? For more information about LINQ, see Language-Integrated Query (LINQ).? To find the latest articles and resources from the Visual C# team, see the Visual C# Developer Center.NET Framework Platform ArchitectureC# programs run on the .NET Framework, an in tegral comp onent of Win dows
19、 that in cludes a virtual executi on system called the com mon Ian guage run time (CLR) and a uni fied set of class libraries. The CLR is the commercial impleme ntati on by Microsoft of the com mon Ian guage in frastructure (CLI), an intern ati onal sta ndard that is the basis for creati ng executi
20、on and developme nt en vir onments in which Ian guages and libraries work together seamlessly.Source code writte n in C# is compiled into an in termediate Ian guage (IL) that con forms to the CLI specificati on. The IL code and resources, such as bitmaps and stri ngs, are stored on disk in an execut
21、able file called an assembly, typically with an exte nsion of .exe or .dll. An assembly contains a man ifest that provides in formatio n about the assemblys types, versi on, culture, and security requireme nts.Whe n the C# program is executed, the assembly is loaded in to the CLR, which might take v
22、arious acti ons based on the in formatio n in the man ifest. Then, if the security requireme nts are met, the CLR performs just in time (JIT) compilati on to con vert the IL code to n ative mach ine in struct ions. The CLR also provides other services related to automatic garbage collecti on, except
23、i on han dli ng, and resource man ageme nt. Code that is executed by the CLR is sometimes referred to as ma naged code, i n con trast to unman aged code which is compiled into n ative mach ine Ian guage that targets a specific system. The followi ng diagram illustrates the compile-time and run-time
24、relatio nships of C# source code files, the .NET Framework class libraries, assemblies, and the CLR.Visual C# Praje:t匚盘S&urceFile(s)uses.NET FrameworkCless LibrariesReferencesCreaieaMaAssem bl (.en& or .dll)MSIL Metdddta1L metadata & references loaded by CLR.MET FrameworkCommon Language SuntimeSectrity / QarbageCollection * JiT CompilerConverted to native wvhlne “deOprdting SystcirLan guage in teroperability is a key feature of the .NET Framework. Because the IL code produced by the C# compiler con forms to the Com mon Ty
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2025广东云浮市云创源投资控股有限公司招聘网络工程部经理1人笔试历年参考题库附带答案详解
- 2025年麻阳锦江发展集团有限责任公司招聘14人笔试历年参考题库附带答案详解
- 2025年重庆西部数据交易有限公司市场化招聘专业人才11人笔试历年参考题库附带答案详解
- 2025年邢台机场有限公司气象等岗位招聘笔试历年参考题库附带答案详解
- 2025城发环保能源(伊川)有限公司招聘5人笔试历年参考题库附带答案详解
- 2025华工科技产业股份有限公司招聘100人+笔试历年参考题库附带答案详解
- 2025上海地铁招聘96名见习人员笔试历年参考题库附带答案详解
- 中医药服务能力评估体系建立课题申报书
- (2026年)神经外科年终工作总结汇报课件
- 健康提升计划
- 外科术后并发症防治手册
- 北京中国新闻社2025年度面向社会招聘10人笔试历年参考题库附带答案详解
- 2026年经济开发区招聘面试企业服务对接实务练习题及解析
- 2025年农产品经纪人专业知识考核试卷及答案
- 华润守正评标专家考试题库及答案
- 2025辽宁沈阳副食集团及所属企业招聘2人参考题库及答案解析(夺冠)
- 北京某高层办公楼施工组织设计(创鲁班奖)
- 2025年业财一体信息化应用1+X证书中级考试(含答案解析)
- 腹痛急诊科常见病处理流程
- 升白针健康科普
- 操场提升方案
评论
0/150
提交评论