Generating and Using .NET Library Files

This section provides a tutorial example on how to compile C# source code files into library files and use them as references when compile other source code files.

If you have a program with multiple C# source code files, you can:

Let's use two source files, "Util.cs" and "SwapTest.cs" described in the previous section to try this:

1. Compile "Util.cs" into a library file, "Util.dll":

   /target:library Util.cs

C:\herong>dir Util.*
     210 Util.cs
   3,072 Util.dll

2. Compile "SwapTest.cs" with reference to the library file, "Util.dll":

C:\herong>\Windows\Microsoft.NET\Framework\v4.0.30319\csc UtilTest.cs
   /reference:Util.dll SwapTest.cs

C:\herong>dir SwapTest.*
     329 SwapTest.cs
   3,072 SwapTest.exe

3. Run the executable file "SwapTest.exe", you will get the program output:

Herong Yang
Yang Herong

Now we learned how to generate and use .NET library files.

Table of Contents

 About This Book

 Introduction of C# (C Sharp)

 Data Type and Variables

 Logical Expressions and Conditional Statements

 Arrays and Loop Statements

 Data Type Features

 Floating-Point Data Types

 Passing Parameters to Methods

 Execution Environment Class

 Visual C# 2010 Express Edition

 Class Features

 C# Compiler and Intermediate Language

Compiling C# Source Code Files

 C# Compiler "csc" Options

 Multiple Classes in a Single Source File

 Compiling Multiple Source Code Files Together

Generating and Using .NET Library Files

 MSBuild - Microsoft Build Engine

 Memory Usages of Processes

 Multithreading in C#

 Async Feature from C# 5

 System.IO.FileInfo Class

 System.Diagnostics.FileVersionInfo Class

 WPF - Windows Presentation Foundation

 Partial Classes and Partial Methods

 Outdated Tutorials


 Full Version in PDF/ePUB