Добавил:
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
Microsoft C# Professional Projects - Premier Press.pdf
Скачиваний:
178
Добавлен:
24.05.2014
Размер:
14.65 Mб
Скачать

840

Part X

APPENDIXES

 

 

 

TIP

You cannot use the checked keyword to track overflow conditions while working with pointers.

C# also allows you to type cast between different pointer types. Consider the following example:

int Integer = 20;

int *Pointer1;

Pointer1 = &Integer;

sbyte *Pointer2 = (sbyte*) Pointer1;

You can only explicitly convert between pointer types. C# does not allow an implicit pointer type conversion.

In this chapter, you learned about pointers and the use of pointers in your program code. After writing code that contains a pointer, you need to compile the code. Compilation of code containing pointers is slightly different from the compilation of an ordinary code.

Compiling Unsafe Code

As discussed earlier, you need to inform the compiler that the code to be executed is marked as unsafe. If you are compiling the program code from the command line, you can add the unsafe flag with the compile command, as shown:

csc /unsafe file1.cs

The preceding statement includes the unsafe flag with the csc command to inform the compiler that the file named file1.cs is marked as unsafe.

You can also compile the unsafe code by setting the Allow unsafe code blocks property to True in Visual Studio .NET. To do this, you can do the following steps:

1.Right-click on the project name in the Solution Explorer window.

2.Click on the Properties option in the drop-down list. The Property Pages page is displayed.