Wei-Meng Lee - C# 2008 Programmer's Reference

Здесь есть возможность читать онлайн «Wei-Meng Lee - C# 2008 Programmer's Reference» весь текст электронной книги совершенно бесплатно (целиком полную версию без сокращений). В некоторых случаях можно слушать аудио, скачать через торрент в формате fb2 и присутствует краткое содержание. Город: Indianapolis, Год выпуска: 2009, ISBN: 2009, Издательство: Wiley Publishing, Inc., Жанр: Программирование, на английском языке. Описание произведения, (предисловие) а так же отзывы посетителей доступны на портале библиотеки ЛибКат.

C# 2008 Programmer's Reference: краткое содержание, описание и аннотация

Предлагаем к чтению аннотацию, описание, краткое содержание или предисловие (зависит от того, что написал сам автор книги «C# 2008 Programmer's Reference»). Если вы не нашли необходимую информацию о книге — напишите в комментариях, мы постараемся отыскать её.

C# 2008 Programmers Reference provides a concise and thorough reference on all aspects of the language. Each chapter contains detailed code samples that provide a quick and easy way to understand the key concepts covered.

C# 2008 Programmer's Reference — читать онлайн бесплатно полную книгу (весь текст) целиком

Ниже представлен текст книги, разбитый по страницам. Система сохранения места последней прочитанной страницы, позволяет с удобством читать онлайн бесплатно книгу «C# 2008 Programmer's Reference», без необходимости каждый раз заново искать на чём Вы остановились. Поставьте закладку, и сможете в любой момент перейти на страницу, на которой закончили чтение.

Тёмная тема
Сбросить

Интервал:

Закладка:

Сделать

Summary

This chapter provided a quick overview of the common features and tools available in Visual Studio 2008. Visual Studio 2008 is highly configurable, so you'll want to take some time to familiarize yourself with the environment. If you're totally new to C#, some Visual Studio features like code refactoring and unit testing may not seem all that important to you now, but once you've gotten some C# under your belt, you'll want to take another look at those features.

When you're ready, the next chapter gets you started in writing code in C#.

Chapter 3

C# Language Foundations

The best way to get started in a new programming language is to create a simple program and then examine the various parts that compose it. With this principle in mind, you'll create a simple C# program — first using Visual Studio 2008 and then using a plain text editor.

In this chapter you build and run the HelloWorld application, using Visual Studio 2008 as well as using the command line. After that, you tackle the syntax of the C# language and all the important topics, such as:

□ C# keywords

□ Variables

□ Constants

□ Comments

□ XML documentation

□ Data types

□ Flow control

□ Loops

□ Operators

□ Preprocessor directives

Using Visual Studio 2008

The easiest way to create your first C# program is to use Visual Studio 2008.

Editions of Visual Studio 2008

You can use any of the following editions of Visual Studio 2008 to create a C# program:

□ Visual C# 2008 Express Edition

□ Visual Studio 2008 Standard Edition

□ Visual Studio 2008 Professional Edition

□ Visual Studio 2008 Team Suite Edition

All the code samples and screen shots shown in this book were tested using Visual Studio 2008 Professional Edition.

1. Launch Visual Studio 2008.

2. Create a new Console Application project by selecting File→New→Project.

3. Expand the Visual C# item on the left of the dialog, and select Windows. Then, select the Console Application template on the right (see Figure 3-1). Name the project HelloWorld.

Figure 31 4 Click OK Figure 32 shows the skeleton of the console - фото 82

Figure 3-1

4. Click OK. Figure 3-2 shows the skeleton of the console application.

Figure 32 5 Type the following highlighted code into the Mainmethod as - фото 83

Figure 3-2

5. Type the following highlighted code into the Main()method as shown:

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

namespace HelloWorld {

class Program {

static void Main(string[] args) {

Console.WriteLine("Hello, world! This is my first C# program!");

Console.ReadLine();

return;

}

}

}

6. To debug the application and see how it looks like when executed, press F5 in Visual Studio 2008. Figure 3-3 shows the output in the Console window.

Figure 33 To return to Visual Studio 2008 press the Enter key and the console - фото 84

Figure 3-3

To return to Visual Studio 2008, press the Enter key and the console window will disappear.

Using the C# Compiler (csc.exe)

Besides using Visual Studio 2008 to compile and run the application, you can build the application using Visual Studio 2008 and use the C# compiler ( csc.exe) to manually compile and then run the application. This option is useful for large projects where you have a group of programmers working on different sections of the application.

Alternatively, if you prefer to code a C# program using a text editor, you can use the Notepad (Programs→Accessories→Notepad) application included in every Windows computer. (Be aware, however, that using Notepad does not give you access to the IntelliSense feature, which is available only in Visual Studio 2008.)

1. Using Notepad, create a text file, name it HelloWorld.cs, and save it into a folder on your hard disk, say in C:\C#.

2. Populate HelloWorld.cswith the following:

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

namespace HelloWorld {

class Program {

static void Main(string[] args) {

Console.WriteLine("Hello, world! This is my first C# program!");

Console.ReadLine();

return;

}

}

}

3. Use the command-line C# compiler ( csc.exe) that ships with Visual Studio 2008 to compile the program. The easiest way to invoke csc.exeis to use the Visual Studio 2008 command prompt, which has all the path references added for you.

4. To launch the Visual Studio 2008 command prompt, select Start→Programs→Microsoft Visual Studio 2008→Visual Studio Tools→Visual Studio 2008 Command Prompt.

5. In the command prompt, change to the directory containing the C# program (C:\C# for this example), and type the following command (see Figure 3-4):

C:\C#>csc HelloWorld.cs

Figure 34 6 Once the program is compiled you will find the HelloWorldexe - фото 85

Figure 3-4

6. Once the program is compiled, you will find the HelloWorld.exe executable in the same directory (C:\C#). Type the following to execute the application (see Figure 3-5):

C:\C#>HelloWorld

Figure 35 7 To return to the command prompt press Enter Dissecting the - фото 86

Figure 3-5

7. To return to the command prompt, press Enter.

Dissecting the Program

Now that you have written your first C# program, let's take some time to dissect it and understand some of the important parts.

The first few lines specify the various namespaces:

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

As mentioned in Chapter 1, all the class libraries in the .NET Framework are grouped using namespaces. In C#, you use the usingkeyword to indicate that you will be using library classes from the specified namespace. In this example, you use the Consoleclass's WriteLine()method to write a message to the console. The Consoleclass belongs to the Systemnamespace, and if you do not have the using Systemstatement at the top of the program, you need to specify the fully qualified name for Console, which is:

System.Console.WriteLine("Hello, world! This is my first C# program!");

The next keyword of interest is namespace. It allows you to assign a namespace to your class, which is HelloWorldin this example:

namespace HelloWorld {

class Program {

static void Main(string[] args) {

Console.WriteLine("Hello, world! This is my first C# program!");

Console.ReadLine();

Читать дальше
Тёмная тема
Сбросить

Интервал:

Закладка:

Сделать

Похожие книги на «C# 2008 Programmer's Reference»

Представляем Вашему вниманию похожие книги на «C# 2008 Programmer's Reference» списком для выбора. Мы отобрали схожую по названию и смыслу литературу в надежде предоставить читателям больше вариантов отыскать новые, интересные, ещё непрочитанные произведения.


Отзывы о книге «C# 2008 Programmer's Reference»

Обсуждение, отзывы о книге «C# 2008 Programmer's Reference» и просто собственные мнения читателей. Оставьте ваши комментарии, напишите, что Вы думаете о произведении, его смысле или главных героях. Укажите что конкретно понравилось, а что нет, и почему Вы так считаете.

x