c#一些概念
来源:互联网 发布:虚拟机网络连接模式 编辑:程序博客网 时间:2024/05/18 02:36
1,#region Windows 窗体设计器生成的代码
#endregion
#region / #endregion 折叠用
2,partial class Form1
partial 修饰 类 接口,结构体,表明他们代码太长要放在几个cs文件中完成;cs中没有头文件的概念,要引用就用using namespace xx
简单的说法:[STAThread]指示应用程序的默认线程模型是单线程单元 (STA)。启动线程模型可设置为单线程单元或多线程单元。
3,用using 包含命名空间时,有时会提示不存在包,此时右键工程,可以增加引用。
4,属性:
Attribute作为编译器的指令
在C#中存在着一定数量的编译器指令,如:#define DEBUG, #undefine DEBUG, #if等。这些指令专属于C#,而且在数量上是固定的。而Attribute用作编译器指令则不受数量限制。比如下面的三个Attribute:
Conditional:起条件编译的作用,只有满足条件,才允许编译器对它的代码进行编译。一般在程序调试的时候使用。
DllImport:用来标记非.NET的函数,表明该方法在一个外部的DLL中定义。
Obsolete:这个属性用来标记当前的方法已经被废弃,不再使用了。
下面的代码演示了上述三个属性的使用:
1#define DEBUG //这里定义条件
2
3using System;
4using System.Runtime.InteropServices;
5using System.Diagnostics;
6
7namespace AttributeDemo
8{
9 class MainProgramClass
10 {
11
12 [DllImport("User32.dll")]
13 public static extern int MessageBox(int hParent, string Message, string Caption, int Type);
14
15 static void Main(string[] args)
16 {
17 DisplayRunningMessage();
18 DisplayDebugMessage();
19
20 MessageBox(0,"Hello","Message",0);
21
22 Console.ReadLine();
23 }
24
25 [Conditional("DEBUG")]
26 private static void DisplayRunningMessage()
27 {
28 Console.WriteLine("开始运行Main子程序。当前时间是"+DateTime.Now);
29 }
30
31 [Conditional("DEBUG")]
32 //[Obsolete("Don't use Old method, use New method", true)]
33 [Obsolete]
34 private static void DisplayDebugMessage()
35 {
36 Console.WriteLine("开始Main子程序");
37 }
38 }
39}
2
3using System;
4using System.Runtime.InteropServices;
5using System.Diagnostics;
6
7namespace AttributeDemo
8{
9 class MainProgramClass
10 {
11
12 [DllImport("User32.dll")]
13 public static extern int MessageBox(int hParent, string Message, string Caption, int Type);
14
15 static void Main(string[] args)
16 {
17 DisplayRunningMessage();
18 DisplayDebugMessage();
19
20 MessageBox(0,"Hello","Message",0);
21
22 Console.ReadLine();
23 }
24
25 [Conditional("DEBUG")]
26 private static void DisplayRunningMessage()
27 {
28 Console.WriteLine("开始运行Main子程序。当前时间是"+DateTime.Now);
29 }
30
31 [Conditional("DEBUG")]
32 //[Obsolete("Don't use Old method, use New method", true)]
33 [Obsolete]
34 private static void DisplayDebugMessage()
35 {
36 Console.WriteLine("开始Main子程序");
37 }
38 }
39}
阅读全文
0 0
- c#一些概念
- C# 一些概念
- C#中容易忽略的一些概念
- C#中一些易混淆概念总结
- C#中一些基本的概念
- 【C#小知识】C#中一些易混淆概念总结
- .NET概念:一些C#预处理器指令(转)
- .net asp.net C# vb.net 一些概念问题
- 一些概念
- 一些概念
- 一些概念
- 一些概念
- 一些概念
- 一些概念
- 一些概念
- 一些概念
- 一些概念
- 一些概念
- java的持久化技术选型
- win7 批处理文件默认以管理员身份运行及清除IE缓存脚本
- Unity制作游戏中技能使用后转CD的场景
- 将一个本地项目提交到git
- 数据结构 — 希尔排序
- c#一些概念
- svn的cleanup失败的解决方案
- 迷宫找最短路径 深度优先—C
- 使用cookie+工具类实现的 记录显示 用户【浏览商品记录】
- echo等追加到文件末尾
- 数据库的垂直切分和水平切分
- hdu2082母函数
- 第十二届湖南省赛:三角形和矩形
- ReactNative接入支付宝支付