第二章 编写C#程序
本章内容:
- Visual Studio 2010和Visual C# 2010 Express Edition的基础知识
- 如何编写简单的控制台应用程序
- 如何编写Windows Form应用程序
2.1开发环境
2.1.1 Visual Studio 2010
2.2 控制台应用程序
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
//Output text to the screem.
Console.WriteLine("The first app in Beginning C# Programming!");
Console.ReadKey();
}
}
}
Console.ReadKey():
等待键盘输入,退出程序。使调试时能看到输出结果。如果没有此句,命令窗口会一闪而过。
新建项目:Ctrl+Shift+N
2.2.1 解决方案资源管理器(Solution Explorer)
2.2.2 属性(Properties)窗口
2.2.3 错误列表(Error List)窗口
2.3 Windows Forms应用程序
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
MessageBox.Show("The first Windows app in the book!");
}
}
}