c#实例源代码教程文件.pdfVIP

  • 39
  • 0
  • 约2.1万字
  • 约 14页
  • 2021-04-03 发布于湖南
  • 举报
c # 实 例 源 代 码 【实例 1-1】 using System; using System.Collections.Generic; using System.Text; namespace _ { class Program { static void Main( string [] args) { System. Console .WriteLine( 恭喜你,学会了 C#编程! ); System. Console .ReadLine(); } } } 【实例 1-2】 private void Form1_Load( object sender, EventArgs e) { this .Text= 这是一窗口! ; Label lbShow = new Label (); lbShow.Location = new Point (40,50); lbShow.AutoSize = true ; lbShow.Text = 恭喜你学会编程了! ; this .Controls.Add(lbShow); int [] x, y; x = new int [5] { 1,2,3,4,5}; y = new int [5]; y = x; foreach ( int a in y) { lbShow.Text += a.ToString(); } this .Controls.Add(lbShow); } 【实例2-1】 using System; using System.Windows.Forms; namespace TestEnum { public partial class TestEnum : Form { //Visual Studio .Net 自动生成的构造函数,后文示例将全部省略 public TestEnum() { InitializeComponent(); } enum MyEnum { a = 101, b, c, d = 201, e, f }; // 声明枚举型 private void TestEnum_Load( object sender, EventArgs e) { MyEnum x = MyEnum.f; // 使用枚举型 MyEnum y = ( MyEnum)202; string result = 枚举数 x 的值为 ; result += ( int )x; // 将 x转换为整数 result += \n 枚举数 y代表枚举元素 + y ; lblShow.Text = result; } } } 【实例2-2】 usin

文档评论(0)

1亿VIP精品文档

相关文档