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», без необходимости каждый раз заново искать на чём Вы остановились. Поставьте закладку, и сможете в любой момент перейти на страницу, на которой закончили чтение.

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

Интервал:

Закладка:

Сделать

Add a new class to the project by right-clicking on the project's name in Solution Explorer and selecting Add→Class (see Figure 15-21).

Figure 1521 Use the default name of Class2cs In the newly added Class2cs - фото 231

Figure 15-21

Use the default name of Class2.cs. In the newly added Class2.cs, code the following:

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

namespace Learn2develop.net {

public class Class2 {

public void DoSomething() {

}

}

}

Class2is enclosed within the same namespace — Learn2develop.net, and it also has a DoSomething()method. Compile the ClassLibrary1project so that an assembly is generated in the bin\Debug folder of the project — ClassLibrary1.dll. Add another Class Library project to the current solution and name the project ClassLibrary2(see Figure 15-22).

Figure 1522 Populate the default Class1csas follows using System - фото 232

Figure 15-22

Populate the default Class1.csas follows:

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

namespace Learn2develop.net {

public class Class3 {

public void DoSomething() {

}

}

}

namespace CoolLabs.net {

public class Class5 {

public void DoSomething() {

}

}

}

This file contains two namespaces — Learn2develop.netand CoolLabs.net— each containing a class and a method.

Compile the ClassLibrary2project so that an assembly is generated in the bin\Debug folder of the project — ClassLibrary2.dll.

Now, add another Class Library project to the current solution, and this time use the Visual Basic language. Name the project ClassLibrary3(see Figure 15-23).

Figure 1523 In the Properties page of the ClassLibrary3project set its root - фото 233

Figure 15-23

In the Properties page of the ClassLibrary3project, set its root namespace to Learn2develop.net(see Figure 15-24).

Figure 1524 In the default Class1vb define Class4and add a method to it - фото 234

Figure 15-24

In the default Class1.vb, define Class4and add a method to it:

Public Class Class4

Public Sub DoSomething()

End Sub

End Class

Compile the ClassLibrary3project so that an assembly is generated in the bin\Debug folder of the project — ClassLibrary3.dll.

Now add a new Windows application project (name it WindowsApp) to the current solution so that you can use the three assemblies ( ClassLibrary1.dll, ClassLibrary2.dll, and ClassLibrary3.dll) that you have created.

To use the three assemblies, you need to add a reference to all of them. Because the assemblies are created in the same solution as the current Windows project, you can find them in the Projects tab of the Add Reference dialog (see Figure 15-25).

Figure 1525 In the codebehind of the default Form1 type the - фото 235

Figure 15-25

In the code-behind of the default Form1, type the Learn2develop.netnamespace, and IntelliSense will show that four classes are available (see Figure 15-26).

Figure 1526 Even though the classes are located in different assemblies - фото 236

Figure 15-26

Even though the classes are located in different assemblies, IntelliSense still finds them because all these classes are grouped within the same namespace. You can now use the classes as follows:

Learn2develop.net.Class1 c1 = new Learn2develop.net.Class1();

c1.DoSomething();

Learn2develop.net.Class2 c2 = new Learn2develop.net.Class2();

c2.DoSomething();

Learn2develop.net.Class3 c3 = new Learn2develop.net.Class3();

c3.DoSomething();

Learn2develop.net.Class4 c4 = new Learn2develop.net.Class4();

c4.DoSomething();

For Class5, you need to use the CoolLabs.netnamespace. If you don't, IntelliSense will check against all the referenced assemblies and suggest an appropriate namespace (see Figure 15-27).

Figure 1527 You can use Class5as follows CoolLabsnetClass5 c5 new - фото 237

Figure 15-27

You can use Class5as follows:

CoolLabs.net.Class5 c5 = new CoolLabs.net.Class5();

c5.DoSomething();

Namespace Alias

There are times when you want to specify the fully qualified name of a class so that your code is easier to understand. For example, you usually import the namespace of a class and use the class like this:

using CoolLabs.net;

//...

Class5 c5 = Class5();

c5.DoSomething();

However, you might want to use the fully qualified name for Class5to make it clear that Class5belongs to the CoolLabs.netnamespace. To do so, you can rewrite your code like this:

CoolLabs.net.Class5 c5 = new CoolLabs.net.Class5();

c5.DoSomething();

But the CoolLabs.net namespace is quite lengthy and may make your code look long and unwieldy. To simplify the coding, you can give an alias to the namespace, like this:

using cl = CoolLabs.net;

//...

cl.Class5 c5 = cl.Class5();

c5.DoSomething();

Then, instead of using the full namespace, you can simply refer to the CoolLabs.netnamespace as cl.

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

Интервал:

Закладка:

Сделать

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

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


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

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

x