close
1: 2: enum Animal
3: { 4: Dog = 0x0001, 5: Cat = 0x0002, 6: Duck = 0x0004, 7: Chicken = 0x0008 8: }9: static void Main(string[] args)
10: { 11: Animal animals = Animal.Dog | Animal.Cat; 12: Console.WriteLine(animals.ToString()); 13: Console.ReadKey(); 14: }加入[Flags]
1: [Flags]2: enum Animal
3: { 4: Dog = 0x0001, 5: Cat = 0x0002, 6: Duck = 0x0004, 7: Chicken = 0x0008 8: }9: static void Main(string[] args)
10: { 11: Animal animals = Animal.Dog | Animal.Cat; 12: Console.WriteLine(animals.ToString()); 13: Console.ReadKey(); 14: }加入[DllImport(“User32.dll”)]
1: using System.Runtime.InteropServices;
2: 3: namespace WindowsFormsApp1
4: {5: public partial class Form1 : Form
6: {7: public Form1()
8: { 9: InitializeComponent(); 10: }11: [DllImport("User32.dll")]
12: public static extern int MessageBox(int hParent, string msg, string caption, int type);
13: 14: 15: private void button1_Click(object sender, EventArgs e)
16: {17: MessageBox(0, "How to use attribute in .NET", "User32.dll", 0);
18: } 19: } 20: }全站熱搜



留言列表
