摘要:为了与欧洲计算机制造商协会 (ECMA) 的 C# 规范完全兼容,Microsoft Corporation 对 C# 编译器的实现进行了几处改动。这些改动将在多方面影响现有的代码,因此用户必须检查他们的代码以确保这些代码符合 C# 编程语言必需的和推荐的使用要求。
目录
背景
偶然发现了百度的空间. 就赶快测试一下. Hello百度~
C# 语言的新功能
实现的改变
小结
背景
2001 年年底,ECMA 将 C# 编程语言批准为一项标准 (ECMA-334)。为了与 Microsoft 在 C# 和公共语言接口 (CLI) 标准化进程方面的举措保持一致,Microsoft 遵循 ECMA C# 标准的精神和文字规范对 C# 编译器进行了几处小的改动。另外,Microsoft 在遵循 C# 标准规范的同时对 C# 实现作了一些额外的小改动,并更正了 C# 程序员遇到的一些编译器问题和错误。其中的每处改动都可能导致使用 Visual C# .NET 2002 版编译器编写的代码在用于 Visual C# .NET 2003 之前必须进行修改。
C# 语言的新功能
Visual C# .NET 2003 版的 C# 语言中添加了两个新功能。第一,编译器现在支持 #line hidden 预处理器指令。#line hidden 指令主要用于源代码生成器,它通知编译器忽略紧跟在 #line hidden 指令后面的所有代码行的调试程序信息,直到遇到下一个 #line 指令为止(该 #line 指令的调试程序信息也一并被忽略),这里假设它们中间不会立即碰到下一个 #line hidden 预处理指令。在下面的示例中,编译器生成了 IL 代码,其中的 WriteLine 语句不包含调试信息。这样,调试应用程序的程序员将无法查看“隐藏”的代码并检查其中的内容:
{
简单的加减乘除实例 C#
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
namespace WinForm_p169_2
{
/// <summary>
/// Form2 的摘要说明。
/// </summary>
public class Form2 : System.Windows.Forms.Form
{
private System.Windows.Forms.ToolBar toolBar1;
private System.Windows.Forms.ToolBarButton toolBarButton1;
private System.Windows.Forms.ToolBarButton toolBarButton2;
private System.Windows.Forms.ToolBarButton toolBarButton3;
private System.Windows.Forms.ToolBarButton toolBarButton4;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.TextBox textBox1;
private System.Windows.Forms.TextBox textBox2;
private System.Windows.Forms.StatusBar statusBar1;
private System.Windows.Forms.StatusBarPanel statusBarPanel1;
private System.Windows.Forms.StatusBarPanel statusBarPanel2;
int a,b,x; // 运算所需的3个变量
/// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.Container components = null;
public Form2()
{
//
// Windows 窗体设计器支持所必需的
//
InitializeComponent();
//
// TODO: 在 InitializeComponent 调用后添加任何构造函数代码
//
}
/// <summary>
/// 清理所有正在使用的资源。
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if(components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows 窗体设计器生成的代码
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.toolBar1 = new System.Windows.Forms.ToolBar();
this.toolBarButton1 = new System.Windows.Forms.ToolBarButton();
this.toolBarButton2 = new System.Windows.Forms.ToolBarButton();
this.toolBarButton3 = new System.Windows.Forms.ToolBarButton();
this.toolBarButton4 = new System.Windows.Forms.ToolBarButton();
this.label1 = new System.Windows.Forms.Label();
this.label2 = new System.Windows.Forms.Label();
this.textBox1 = new System.Windows.Forms.TextBox();
this.textBox2 = new System.Windows.Forms.TextBox();
this.statusBar1 = new System.Windows.Forms.StatusBar();
this.statusBarPanel1 = new System.Windows.Forms.StatusBarPanel();
this.statusBarPanel2 = new System.Windows.Forms.StatusBarPanel();
((System.ComponentModel.ISupportInitialize)(this.statusBarPanel1)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.statusBarPanel2)).BeginInit();
this.SuspendLayout();
//
// toolBar1
//
this.toolBar1.Buttons.AddRange(new System.Windows.Forms.ToolBarButton[] {
this.toolBarButton1,
this.toolBarButton2,
this.toolBarButton3,
this.toolBarButton4});
this.toolBar1.DropDownArrows = true;
this.toolBar1.Location = new System.Drawing.Point(0, 0);
this.toolBar1.Name = "toolBar1";
this.toolBar1.ShowToolTips = true;
this.toolBar1.Size = new System.Drawing.Size(292, 41);
this.toolBar1.TabIndex = 0;
this.toolBar1.ButtonClick += new System.Windows.Forms.ToolBarButtonClickEventHandler(this.toolBar1_ButtonClick);
//
// toolBarButton1
//
this.toolBarButton1.Tag = "+";
this.toolBarButton1.Text = "加";
//
// toolBarButton2
//
this.toolBarButton2.Tag = "-";
this.toolBarButton2.Text = "减";
//
// toolBarButton3
//
this.toolBarButton3.Tag = "*";
this.toolBarButton3.Text = "乘";
//
// toolBarButton4
//
this.toolBarButton4.Tag = "/";
this.toolBarButton4.Text = "除";
//
// label1
//
this.label1.Location = new System.Drawing.Point(27, 79);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(63, 27);
this.label1.TabIndex = 1;
this.label1.Text = "第一个数";
//
// label2
//
this.label2.Location = new System.Drawing.Point(25, 133);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(63, 27);
this.label2.TabIndex = 2;
this.label2.Text = "第二个数";
//
// textBox1
//
this.textBox1.Location = new System.Drawing.Point(94, 77);
this.textBox1.Name = "textBox1";
this.textBox1.Size = new System.Drawing.Size(129, 21);
this.textBox1.TabIndex = 3;
this.textBox1.Text = "0";
//
// textBox2
//
this.textBox2.Location = new System.Drawing.Point(92, 130);
this.textBox2.Name = "textBox2";
this.textBox2.Size = new System.Drawing.Size(129, 21);
this.textBox2.TabIndex = 4;
this.textBox2.Text = "0";
//
// statusBar1
//
this.statusBar1.Location = new System.Drawing.Point(0, 251);
this.statusBar1.Name = "statusBar1";
this.statusBar1.Panels.AddRange(new System.Windows.Forms.StatusBarPanel[] {
this.statusBarPanel1,
this.statusBarPanel2});
this.statusBar1.ShowPanels = true;
this.statusBar1.Size = new System.Drawing.Size(292, 22);
this.statusBar1.TabIndex = 5;
this.statusBar1.Text = "statusBar1";
//
// statusBarPanel1
//
this.statusBarPanel1.Text = "结果";
//
// Form2
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(292, 273);
this.Controls.Add(this.statusBar1);
this.Controls.Add(this.textBox2);
this.Controls.Add(this.textBox1);
this.Controls.Add(this.label2);
this.Controls.Add(this.label1);
this.Controls.Add(this.toolBar1);
this.Name = "Form2";
this.Text = "Form2";
((System.ComponentModel.ISupportInitialize)(this.statusBarPanel1)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.statusBarPanel2)).EndInit();
this.ResumeLayout(false);
}
#endregion
// 函数验证是否为数字
public bool IsNumeric(string str)
{
try
{
// 先判断是否为整形
Int32.Parse(str);
}
catch
{
// 在判断是否为浮点型
try
{
Double.Parse(str);
}
catch
{
return false;
}
}
return true;
}
// 运算函数
public void NumOperation(string o)
{
// 判断输入是否为空
if((textBox1.Text!=null)||(textBox2.Text!=null))
{
// 判断是否为数字
if(!IsNumeric(textBox1.Text)||!IsNumeric(textBox2.Text))
{
this.textBox1.Text="0";
this.textBox2.Text="0";
}
else
{
// 转换输入的2个字符串为数字
a=System.Convert.ToInt32(this.textBox1.Text);
b=System.Convert.ToInt32(this.textBox2.Text);
if(o=="+")
x=a+b;
if(o=="-")
x=a-b;
if(o=="*")
x=a*b;
if(o=="/")
if(b==0)
{
MessageBox.Show("除数不能为0!");
this.textBox2.SelectAll();
}
else
x=a/b;
// 显示结果
statusBarPanel2.Text=x.ToString();
}
}
}
private void toolBar1_ButtonClick(object sender, System.Windows.Forms.ToolBarButtonClickEventArgs e)
{
// 调用按钮
this.NumOperation(e.Button.Tag.ToString());
}
}
}
Hello百度~