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

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

Интервал:

Закладка:

Сделать

public bool ValidateEmail(string email) {

string strRegEx = @"^([a-zA-Z0-9_\-\.]+)@((\[[0-9]{1,3}" +

@"\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([a-zA-Z0-9\-]+\" +

@".)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$";

Regex regex = new Regex(strRegEx);

if (regex.IsMatch(email)) return (true);

else return (false);

}

}

}

Instead of using Visual Studio 2008 to build the project into an assembly, use the C# compiler to manually compile it into a module.

To use the C# compiler, launch the Visual Studio 2008 Command Prompt (Start→Programs→Microsoft Visual Studio 2008→Visual Studio Tools→Visual Studio 2008 Command Prompt).

Navigate to the folder containing the StringUtilproject, and type in the following command to create a new module:

csc /target:module /out:StringUtil.netmodule Class1.cs

When the compilation is done, the StringUtil.netmodulefile is created (see Figure 15-12).

Figure 1512 Do the same for the MathUtilclass that you created earlier see - фото 222

Figure 15-12

Do the same for the MathUtilclass that you created earlier (see Figure 15-13):

csc /target:module /out:MathUtil.netmodule Class1.cs

Figure 1513 Copy the two modules that you have just created - фото 223

Figure 15-13

Copy the two modules that you have just created — StringUtil.netmoduleand MathUtil.netmodule— into a folder, say C:\Modules\. Now to combine these two modules into an assembly, type the following command:

csc /target:library /addmodule:StringUtil.netmodule /addmodule:MathUtil.netmodule /out:Utils.dll

This creates the Utils.dllassembly (see Figure 15-14).

Figure 1514 In the WindowsAppUtilsproject remove the previous versions of - фото 224

Figure 15-14

In the WindowsApp-Utilsproject, remove the previous versions of the MathUtil.dllassembly and add a reference to the Utils.dllassembly that you just created (see Figure 15-15). You can do so via the Browse tab of the Add Reference dialog (navigate to the directory containing the modules and assembly, C:\Modules). Click OK.

Figure 1515 In the codebehind of Form1 modify the following code as shown - фото 225

Figure 15-15

In the code-behind of Form1, modify the following code as shown:

namespace WindowsApp_Util {

public partial class Form1 : Form {

public Form1() {

InitializeComponent();

}

private void Form1_Load(object sender, EventArgs e) {

CallMathUtil();

CallStringUtil();

}

private void CallMathUtil() {

MathUtil.Utils util = new MathUtil.Utils();

MessageBox.Show(util.Fibonacci(7).ToString());

}

private void CallStringUtil() {

StringUtil.Utils util = new StringUtil.Utils();

MessageBox.Show(util.ValidateEmail(

"weimenglee@learn2develop.net").ToString());

}

}

}

The CallMathUtil()function invokes the method defined in the MathUtilmodule. The CallStringUtil()function invokes the method defined in the StringUtilmodule.

Set a break point in the Form1_Loadevent handler, as shown in Figure 15-16, and press F5 to debug the application.

Figure 1516 When the breakpoint is reached view the Modules window - фото 226

Figure 15-16

When the breakpoint is reached, view the Modules window (Debug→Windows→Modules), and note that the Utils.dllassembly has not been loaded yet (see Figure 15-17).

Figure 1517 Press F11 to step into the CallMathUtilfunction and observe - фото 227

Figure 15-17

Press F11 to step into the CallMathUtil()function, and observe that the Utils.dllassembly is now loaded, together with the MathUtil.netmodule(see Figure 15-18).

Figure 1518 Press F11 a few times to step out of the CallMathUtilfunction - фото 228

Figure 15-18

Press F11 a few times to step out of the CallMathUtil()function until you step into CallStringUtil(). See that the StringUtil.netmoduleis now loaded (see Figure 15-19).

Figure 1519 This example proves that modules in an assembly are loaded only - фото 229

Figure 15-19

This example proves that modules in an assembly are loaded only as and when needed. Also, when deploying the application, the Util.dllassembly and the two modules must be in tandem. If any of the modules is missing during runtime, you will encounter a runtime error, as shown in Figure 15-20.

Figure 1520 Understanding Namespaces and Assemblies As you know from - фото 230

Figure 15-20

Understanding Namespaces and Assemblies

As you know from Chapter 1, the various class libraries in the .NET Framework are organized using namespaces. So how do namespaces relate to assemblies? To understand the relationship between namespaces and assemblies, it's best to take a look at an example.

Create a new Class Library project in Visual Studio 2008, and name it ClassLibrary1. In the default Class1.cs, populate it with the following:

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

namespace Learn2develop.net {

public class Class1 {

public void DoSomething() {

}

}

}

Observe that the definition of Class1is enclosed within the Learn2develop.netnamespace. The class also contains the DoSomething()method.

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

Интервал:

Закладка:

Сделать

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

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


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

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

x