实验1-2
实验代码:
using System;
namespace test1_2
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Hello World!");
}
}
}
实验结果:

实验1-3:
A.
新建一个button,输入实验书中注释2的代码
实验代码:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace test1_3
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{
MessageBox.Show("Hello World!");
}
}
}
实验结果:
点击button1后,出现窗口hello world

B:
省略注释1所在的行,重新编译,观察运行结果如下

错误提示,缺少Windows.Forms的using指令集
将注释2的代码改为MessageBox.Show(“Hello World!”,”Message from C#”);
实验代码如下:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace test1_3
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{
MessageBox.Show("Hello World!", "Message from C#");
}
}
}
实验结果如下:

实验1-4:
新建一个Web应用程序,新建一个button和label,然后排列一下,输入实验书的代码,实验代码如下:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace test1_4
{
public partial class _Default : Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
Label1.Text = "Hello World!";
}
}
}
实验结果如图,点击button后label变化:


© 版权声明
文章版权归作者所有,未经允许请勿转载。
THE END
暂无评论内容