Preface (Supplement) and Chapter 3 The first C # Program

Source: Internet
Author: User

Preface
0.1 Summary
Read Presenting C #). This book is a shortcut for you to improve your enterprise programming language. This enterprise programming language comes with the next generation of coding
NGWS Runtime: C # (pronounced "C sharp ").
NGWS Runtime is a dynamic environment that not only manages Execution Code, but also makes programming easier. The compiler generates managed code to point to this
Manage the execution environment. You get cross-platform language integration, cross-platform language Exception Handling, enhanced security, version control, arrangement support, and error detection services.
C # is the main language that supports NGWS Runtime #. Many programs that support the NGWS framework are written in C #. Therefore, in some compilers with NGWS Runtime
Its compiler can be considered to be very tested and optimized. C # language uses C ++ for reference, but it is modern and new type security --
Make C # The preferred language for enterprise solutions.

0.2 who should read this book
This book is not suitable for you if you are unfamiliar with programming. This book attempts to free programmers from using C # based on their existing knowledge. Presentation
C # aims at programmers who have experience in C/C ++, VB, Java or other programming.
If you have a C ++ background, it will be easy to switch to C #. However, if you are proficient in other languages, this book will also consume some of your days. For example
If you have a little knowledge about COM programming, this will be more interesting, but it will no longer be necessary for COM programming.

How to organize this book 0.3
Chapter 1 C # introduction -- This chapter takes you to C # for a stroll and answers questions about how to consider learning C.
Chapter 2 NGWS Runtime technical basis-introduces the Low-layer architecture provided by NGWS Runtime for running C # code.
Chapter 3 first C # Application -- create the first C # application (otherwise, what is it ?), It is a "Hello World" application.
.
Chapter 4 C # type -- you can see various types used in the C # application. Explore the differences between the value type and the reference type, as well as how to add and remove boxes.
Chapter 5 Class C # is a sign of true power. It is class-oriented object-oriented programming. You will learn many things, such as constructor and analysis.
Constructors, methods, attributes, indexes, and events.
Chapter 6 control statements-Implement Process Control for applications. Explore the various options and statement provided by C.
Chapter 7 Exception Handling-get the application skills for compiling and implementing Exception Handling. With this skill, you are a good developer in the NGWS Runtime world.
Of citizens
Chapter 8 use C # To write components -- use C # To build components. Because NGWS Runtime is supported, it can be used by customers of different language platforms.
Chapter 9 configuration and arrangement-learn how to use C # Conditional compilation and how to automatically create documents for your C # source code. In addition
Chapter describes the NGWS version technical issues.
Chapter 10 interaction with unmanaged code -- discover how you use the unmanaged code in C # And how the unmanaged code interacts with your C # component
Interoperability.
Chapter C # code error checking-get the skills to use the SDK error checking tool to accurately locate and modify errors in the application.
Chapter 2 Security: exploring the concept of NGWS Runtime security. Learn about code access security and role-based security.

0.4 what do you need to use this book?
From the perspective of this book, all you need is the next-generation windows service software development kit (ngws sdk ). Although at least as long as there are NGWS Runtime and C #
The compiler is fine, but when you explore these exciting new technology features, you can install instruction files and all the SDK tools (including
Debugger), will be an excellent idea.
This book does not require any tools installed on your machine in Visual Studio 7. I only recommend that you have an excellent program editor that supports the number of lines.
To edit the C # source file.
......
(Omit some paragraphs related to the publishing process and express gratitude)

0.5 about the author
Christoph Wille, Microsoft System Engineer (MCSE), Microsoft system developer (MCSD), Netware Network Administrator (CNA) and MCP-IT, as
Web consultants and programmers are especially proficient in Windows DNA. Microsoft regards him as the most valuable person (MVP) in ASP, and he is an early developer with Microsoft.
Of C.
Christoph has written several books independently or independently, including Sams press's "21 days of self-study ADO2.5", "24 hours of self-study ASP", and "self-study ".
MCSE TCP/IP 14 days and MCSE Training Guide: SQL Server 7 management.



Chapter 3 first C # Application

3.0 select an editor
Although I am a stubborn Notepad, I do not recommend using it to edit the source code this time. The reason is that you are dealing with real programming languages, using
Notepad may generate a large number of error lines during source code compilation (C ++ programmers know what I'm talking about .)
You have several options. You can reconfigure the trusted legacy Visual C ++ 6.0 so that it can work with the C # source file. The second option is to use
New Visual Studio 7. Third, you can use any third-party program editor. It is best to support line numbers, color encoding, tool integration, and good search performance.
Yes. CodeWright is one of the examples, as shown in 3.1.

Figure 3.1 CodeWright is one of the many possible editors you can use to create a C # code file.

Of course, none of the mentioned Editors is necessary to create a C # program. You can edit it with Notepad. However, if you consider
To write a bigger project, it is best to give up.

3.1 "Hello World" code
The discussion editor is a little digress. Let's turn the topic back to a very famous small application. For the shortest C # version application, see the list.
3.1. Save it as a file named helloworld. cs so that you can follow the instructions to complete other additional steps, such as compiling an application.

Listing 3.1 The simplest "Hello World" program

1: class HelloWorld
2 :{
3: public static void Main ()
4 :{
5: System. Console. WriteLine ("Hello World ");
6 :}
7 :}

In C #, a code block (statement group) is enclosed by a large arc ({And. So, even if you have no experience with C ++ before, you can also say the Main () method
Is part of the HelloWorld class statement, because the class is included in the defined Large arc.
C # The entry point of an application (executable) is the static Main method, which must be included in a class. Only one class can use this flag to define,
Unless you tell the Compiler which Main method should be used (no side will produce a compilation error ).
Compared with C ++, the first letter of Main is uppercase M, rather than the lowercase letters you have used. In this method, your program starts and ends
. You can call other methods in the method-for example, output text-or create an object and activate the method.
As you can see, the Main method returns a void type.
Public static void Main ()
Even though C ++ programmers may feel familiar with these statements, they are not the same for other programmers. First, the public access flag
This method can be accessed by any program, which is necessary for its call. Second, static means that you can call
Method-all you have to do is call the method by class name.
HelloWorld. Main ();
However, I do not agree to execute this line of code in the Main method. recursion will cause stack overflow.
Another important aspect is the return type. For method Main, you can select void (meaning there is no return value at all), or use int as the integer result (
The error level returned by the Program ). Therefore, the two possible Main methods are:
Public static void Main ()
Public static int Main ()

C ++ programmers will also know

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.