using System; //using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms;
using System.Runtime.InteropServices;
namespace WindowsFormsApplication16 { public partial class Form1 : Form { public Form1() { InitializeComponent(); }
类似DllImport的称为“属性类”,但这个“属性”不同于类的“属性”,.Net中有很多类似的属性类,他们中有一部分用于向编译器提供信息,例如STAThreadAttribute(说明应用程序的 COM 线程模型是单线程单元,一般出现在Main方法前)或FlagsAttribute(用在枚举上,说明该枚举可以进行按位运算);另外一部分用于提供指定的功能,如您提到的DllImportAttribute类(说明该方法是存在于非托管动态链接库中的);还有一些是提供指定的功能,如ComVisibleAttribute(表示程序集中的托管类型对COM是可见的,这个属性类一般出现在AssemblyInfo.cs文件中;另外还有一类就是用户自定义的属性类。