ImageVerifierCode 换一换
格式:DOCX , 页数:23 ,大小:31.56KB ,
资源ID:5850425      下载积分:3 金币
快捷下载
登录下载
邮箱/手机:
温馨提示:
快捷下载时,用户名和密码都是您填写的邮箱或者手机号,方便查询和重复下载(系统自动生成)。 如填写123,账号就是123,密码也是123。
特别说明:
请自助下载,系统不会自动发送文件的哦; 如果您已付费,想二次下载,请登录后访问:我的下载记录
支付方式: 支付宝    微信支付   
验证码:   换一换

加入VIP,免费下载
 

温馨提示:由于个人手机设置不同,如果发现不能下载,请复制以下地址【https://www.bdocx.com/down/5850425.html】到电脑端继续下载(重复下载不扣费)。

已注册用户请登录:
账号:
密码:
验证码:   换一换
  忘记密码?
三方登录: 微信登录   QQ登录  

下载须知

1: 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。
2: 试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓。
3: 文件的所有权益归上传用户所有。
4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
5. 本站仅提供交流平台,并不能对任何下载内容负责。
6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

版权提示 | 免责声明

本文(IntroToCSharpArticle40.docx)为本站会员(b****5)主动上传,冰豆网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知冰豆网(发送邮件至service@bdocx.com或直接QQ联系客服),我们立即给予删除!

IntroToCSharpArticle40.docx

1、IntroToCSharpArticle40 ArticleIntro to C# (vs. Objective-C and Java)Document version: 1.0.0Last updated: 10/31/2018ContentsOverview 3Objectives 3Introduction to C# 3“Hello C#!” 6.NET Runtime 9.NET and C# Program Basics 10C# Classes 12C# Structs 16C# Delegates & Events 17Garbage Collection 19Java Pro

2、grammer Point of View 21Objective-C Programmer Point of View 22Summary 23OverviewC# (pronounced C sharp) is a simple, modern, object-oriented, and type-safe programming language. It will immediately be familiar to C/C+ and Java programmers. C# combines the high productivity of Rapid Application Deve

3、lopment (RAD) languages and the raw power of C+.This article introduces C#, and compares it to other modern object-oriented languages like Objective-C and Java.Objectives When youve finished the article, you will have: A high-level understanding of the C# programming language. A high-level understan

4、ding of the .NET framework. A clear view of the differences and similarities in the implementation of basic scenarios in C# versus Java and Objective-C.Introduction to C#C# is an object-oriented language that enables programmers to build quickly a wide range of applications for the Microsoft .NET fr

5、amework. The goal of C# and the .NET framework is to shorten development time by freeing the developer from worrying about several low-level programming tasks such as memory management, type safety issues, standard libraries, array bounds checking, and so on. This allows developers to spend the majo

6、rity of development time working on their applications and business logic instead. C# is a simple, modern object-oriented and type-safe programming language. Let us see why.Simple Being a part of the Microsoft .NET platform, C# applications receive support from the runtime, and they use services pro

7、vided by the runtime. The .NET framework is a managed environment: the runtime manages memory allocationthis frees the developer from that task. Programmers do not have to deal with the burden of memory management and eliminating memory leaks. C# supports operator overloading, similarly to C+; Java

8、and Objective-C do not support it. Inheritance-related features are clearer and more precise than in C+:An abstract keyword is used instead of declaring pure virtual functions.Abstract classes are declared as such directly by using the abstract keyword, not indirectly by lack of method/function impl

9、ementation (pure virtual functions). An abstract class may be completely implemented and yet be declared abstract for architectural reasons. An override keyword is used for overriding a virtual method. New class member types, such as properties and indexers, are introduced to simplify common tasks s

10、uch as list iteration and property getting and setting. Less Error ProneC# is less error-prone than C+ due to the following characteristics: Unlike C+, where it is possible to declare any type of pointer and assign it to any allocated address or cast it to any other type, C# allows only type-safe ca

11、sting. Casting errors are detected at either compile time or at run time. However, in either situation, you will not miss any errors. The use of Generic types allows template classes to remain type-safe at compile time. This allows the programmer to detect errors during compile, rather than at run t

12、ime. Running under the managed CLR, bounds checking is performed for managed arrays automatically while accessing the allocated array member object. This prevents accidental memory corruption.ModernC# is designed to meet modern application requirements, as well as integrating modern software concept

13、s: C#, as a .NET language, provides a larger set of basic types, including for example the Decimal type used to handle financial applications correctly. Known concepts, such as enumerated types, bit flags, first-class functions and others, become first-class citizen types with a rich set of function

14、alities that represent type-specific usage requirements. It contains a built-in exception-handling mechanism. C# provides a built-in event handler for simpler handling of integrated (for example, GUI and Web) application requirements. C# provides a complete reflection mechanism, allowing object meta

15、data to be explored during run time.Object OrientedC# supports the three pillars of Object-Oriented Programming: EncapsulationA class has tools to hide its implementation details and be responsible for its objects state InheritanceThe “is a” relationship can be defined between classes, enabling exte

16、nsibility and reusability PolymorphismA program can handle different types of objects identically, sharing the same base, having polymorphic behavior, based on specific object typesEverything in C# is part of a type (for example, class, interface, and struct). There are no “global” (non-member) func

17、tions or variables.Every type instance “is an object.” All types are derived from a common base class: object.While these concepts are very familiar to Java developers, they are fundamentally different (and in some cases even completely new) for C/C+/Objective-C developers.A few words about JavaJava

18、 is a programming language originally developed by James Gosling at Sun Microsystems and released in 1995 as a core component of Sun Microsystems Java platform. The language derives much of its syntax from C and C+ but has a simpler object model and fewer low-level facilities. Java applications typi

19、cally are compiled to bytecode (class file) that can run on any Java Virtual Machine (JVM) regardless of computer architecture. Java is general-purpose, concurrent, class-based, and object-oriented. It is designed specifically to have as few implementation dependencies as possible.A few words about

20、Objective-CThe Objective-C language is a simple computer language designed to enable sophisticated object-oriented programming. Objective-C is defined as a small but powerful set of extensions to the standard ANSI C language. It is possible to compile any C program with an Objective-C compiler, and

21、to freely include C code within an Objective-C class. Its additions to C are mostly inspired by Smalltalk, one of the first object-oriented programming languages. All of the syntax for non-object-oriented operations (including primitive variables, preprocessing, expressions, function declarations, a

22、nd function calls) is identical to C, while the syntax for object-oriented features is an implementation of Smalltalk-style messaging. Today, Objective-C is used primarily on Apples Mac OS X and iOS: two environments based on the OpenStep standard, though not compliant with it. Objective-C is the pr

23、imary language used for Apples Cocoa API, and it was originally the main language on NeXTs NeXTSTEP OS. “Hello C#!”Historically, all articles about programming languages start with a “Hello World!” sample. This article will follow this traditionhere is a C# version of this popular program:C#using Sy

24、stem;class HelloApp static void Main() Console.WriteLine(Hello C#!); This code references the System namespace, which provides the Console class, declares a class and enclosed Main static method, which, in turn, calls the Console classs WriteLine static method to output a string.Note: Running the ab

25、ove sample directly under Windows Phone 7 will not produce any tangible output, as the Windows Phone 7 console is not accessible. The code provided is only for comparison.Let us see the same program written in Java:Javapublic class HelloWorld public static void main(String args) System.out.println(H

26、ello Java!); And now in Objective-C:Objective-C#import int main( int argc, const char *argv ) printf( Hello Objective-C!n ); return 0;The first difference is in code organization: while both C# and Java have a class with one method, Objective-C has just a method. The second difference lies in the si

27、gnature of the method: in C#, the “Main” method must start with capital “M”, while in Java and Objective-C, it is not a requirement. The “String” argument for the “Main” method in C# is optional.The third difference is in the “Main” methods return type: in C# (and Java), it returns void while in Obj

28、ective-C it returns “int”. In C#, the Main method could also return an “int” value.The more we examine the code the more differences we will discover.Defining a ClassMuch of object-oriented programming consists of writing code for new objectsdefining new classes. The class definitions in C# and Java

29、 are fairly similar:C# (and Java)class Fraction public int numerator; public int denominator; public void Print() /C# Console.WriteLine(0/1, numerator, denominator); /Java /System.out.println(new PrintfFormat(%d/%d).sprintf(numerator, denominator); In Objective-C, classes are defined in two parts:1.

30、 An interface that declares the methods and instance variables of the class and names its superclass2. An implementation that actually defines the class (contains the code that implements its methods)Typically, these are split between two files, though sometimes a class definition may span several f

31、iles by using a feature called a “category.” The same class/interface written in Objective-C:Objective-C#import interface Fraction: NSObject int numerator; int denominator;-(void) print;-(void) setNumerator: (int) n;-(void) setDenominator: (int) d;-(int) numerator;-(int) denominator;endObjective-C#import Fraction.h#import implementation Fraction-(void) print printf( %i/%i, numerator, denominator );-(void) setNumerator: (int) n numerator = n;-(void) setDenominator: (int) d denominator = d;-(int) denominator return denominat

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1