引用外部程序集:
先看一个程序代码实例:
using System;
using System.Drawing;
using System.Windows.Forms;
namespace TestWin
{
public class SimpleForm : Form
{
public SimpleForm()
{
InitializeComponent();
}
private System.ComponentModel.IContainer components = null;
protected override void Dispose(bool disposing)
{
if(disposing)
{
if(components != null)
{
components.Dispose();
}
}
base.Dispose(disposing);
}
private void InitializeComponent()
{
this.SuspendLayout();
this.AutoScaleDimensions = new System.Drawing.SizeF(6F,12F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(292,273);
this.Name = "SimpleForm";
this.Text = "SimpleForm";
this.ResumeLayout(false);
}
[STAThread]
private static void Main(string[] args)
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new SimpleForm());
}
}
}
在这个程序中,开始的时候使用using语句引用几个外部程序集,在编译的时候需要使用参数r 【reference】将使用到的程序集添加到编译时的引用中去,在引用程序集的时候,可以添加多个程序集,之间使用分隔号隔开就可以了。
上面这个程序运行的命令是:
运行的结果: