外文文献
The C# programming language was created in the spirit of the C and C programming languages. This accounts for its powerful features and easy learning curve. The same cant be said for C and C , but because C# was created from the ground up, Microsoft took the liberty of removing some of the more burdensome features — such as pointers. This section takes a look at the C and C languages, tracing their evolution into C#.
The C programming language was originally designed for use on the UNIX operating system. C was used to create many UNIX applications, including a C compiler, and was eventually used to write UNIX itself. Its widespread acceptance in the academic arena expanded to include the commercial world, and software vendors such as Microsoft and Borland released C compilers for personal computers. The original Windows API was designed to work with Windows code written in C, and the latest set of the core Windows operating system APIs remain compatible with C to this day.
After the notion of object-oriented development began to gain acceptance, it became clear that C needed to be refined to embrace this new way of thinking about code. C was created to embody this refinement. It was designed to be backwardly compatible with C (such that all C programs would also be C programs and could be compiled with a C compiler). The major addition to the C language was support for this new object concept. The C language added support for classes (which are 'templates' of objects), and enabled an entire generation of C programmers to think in terms of objects and their behavior.
Because of the C design goal of retaining backward compatibility with C, C was unable to break away from the low level nature of C.
Microsoft designed C# to retain much of the syntax of C and C . Developers who are familiar with those languages can pick up C# code and begin coding relatively quickly. The big advantage to C#, however, is that its designers chose not to make it backwardly compatible with C and C . While this may seem like a bad deal, its actually good news. C# eliminates the things that makes C and C difficult to work with. Because all C code is also C code, C had to retain all of the original quirks and deficiencies found in C. C# is starting with a clean slate and without any compatibility requirements, so it can retain the strengths of its predecessors and discard the weaknesses that made life hard for C and C programmers.
Introducing C#
C#, the new language introduced in the .NET Framework, is derived from C . However, C# is a modern, objected-oriented (from the ground up) type-safe language.
Language features
The following sections take a quick look at some of the features of the C# language. If some of these concepts dont sound familiar to you, dont worry. All of them are covered in detail in later chapters.
Classes
All code and data in C# must be enclosed in a class. You cant define a variable outside of a class, and you cant write any code thats not in a class. Classes can have constructors, which execute when an object of the class is created, and a destructor, which executes when an object of the class is destroyed. Classes support single inheritance, and all classes ultimately derive from a base class called object. C# supports versioning techniques to help your classes evolve over time while maintaining compatibility with code that uses earlier versions of your classes.
As an example, take a look at a class called Family. This class contains the two static fields that hold the first and last name of a family member as well as a method that returns the full name of the family member.
class Class1
{
public string FirstName;
public string LastName;
public string FullName()
{
}
return FirstName LastName;
}
Note Single inheritance means that a C# class can inherit from only one base class. C# enables you to group your classes into a collection of classes called a namespace. Namespaces have names, and can help organize collections of classes into logical groupings. As you begin to learn C#, it becomes apparent that all namespaces relevant to the .NET Framework begin with System. Microsoft has also chosen to include some classes that aid in backwards compatibility and API access. These classes are contained within the Microsoft namespace.
Data types
C# lets you work with two types of data: value types and reference types. Value types hold actual values. Reference types hold references to values stored elsewhere in memory. Primitive types such as char, int and float, as well as enumerated values and structures, are value types. Reference types hold variables that deal with objects and arrays. C# comes with predefined reference types (object and string), as well as predefined value types (sbyte, short, int, long, byte, ushort, uint, ulong, float, double, bool, char, and decimal). You can also define your own value and reference types in your code. All value and reference types ultimately derive from a base type called object.
Functions
A function is a callable piece of code that may or may not return a value to the code that originally called it. An example of a function would be the FullName function shown earlier, in this chapter, in the Family class. A function is generally associated to pieces of code that return information whereas a method generally does not return information. For our purposes however, we generalize and refer to them both as functions.
Functions can have four kinds of parameters:
bull; Input parameters have values that are sent into the function, but the function cannot change those values.
bull; Output parameters have no value when they are sent into the function, but the function can give them a value and send the value back to the
剩余内容已隐藏,支付完成后下载完整资料
英语译文共 10 页,剩余内容已隐藏,支付完成后下载完整资料
资料编号:[613925],资料为PDF文档或Word文档,PDF文档可免费转换为Word
课题毕业论文、外文翻译、任务书、文献综述、开题报告、程序设计、图纸设计等资料可联系客服协助查找。