⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 form1.cs

📁 大家赶快下载吧
💻 CS
字号:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;

namespace exam1
{
	/// <summary>
	/// Form1 的摘要说明。
	/// </summary>
	public class Form1 : System.Windows.Forms.Form
	{
		private System.Windows.Forms.Button btnT1;
		private System.Windows.Forms.Button btnP127;
		private System.Windows.Forms.Button btnOpera;
		private System.Windows.Forms.Button btnP129;
		private System.Windows.Forms.Button btnTest;
		private System.Windows.Forms.Label label1;
		private System.Windows.Forms.Button button1;
		/// <summary>
		/// 必需的设计器变量。
		/// </summary>
		private System.ComponentModel.Container components = null;

		public Form1()
		{
			//
			// 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.btnT1 = new System.Windows.Forms.Button();
			this.btnP127 = new System.Windows.Forms.Button();
			this.btnOpera = new System.Windows.Forms.Button();
			this.btnP129 = new System.Windows.Forms.Button();
			this.btnTest = new System.Windows.Forms.Button();
			this.label1 = new System.Windows.Forms.Label();
			this.button1 = new System.Windows.Forms.Button();
			this.SuspendLayout();
			// 
			// btnT1
			// 
			this.btnT1.Location = new System.Drawing.Point(16, 168);
			this.btnT1.Name = "btnT1";
			this.btnT1.Size = new System.Drawing.Size(88, 24);
			this.btnT1.TabIndex = 0;
			this.btnT1.Text = "类型区别";
			this.btnT1.Click += new System.EventHandler(this.btnT1_Click);
			// 
			// btnP127
			// 
			this.btnP127.Location = new System.Drawing.Point(128, 168);
			this.btnP127.Name = "btnP127";
			this.btnP127.Size = new System.Drawing.Size(80, 24);
			this.btnP127.TabIndex = 1;
			this.btnP127.Text = "类成员演示";
			this.btnP127.Click += new System.EventHandler(this.btnP127_Click);
			// 
			// btnOpera
			// 
			this.btnOpera.Location = new System.Drawing.Point(232, 168);
			this.btnOpera.Name = "btnOpera";
			this.btnOpera.Size = new System.Drawing.Size(80, 24);
			this.btnOpera.TabIndex = 2;
			this.btnOpera.Text = "操作符重载";
			this.btnOpera.Click += new System.EventHandler(this.btnOpera_Click);
			// 
			// btnP129
			// 
			this.btnP129.Location = new System.Drawing.Point(336, 168);
			this.btnP129.Name = "btnP129";
			this.btnP129.Size = new System.Drawing.Size(64, 24);
			this.btnP129.TabIndex = 3;
			this.btnP129.Text = "委托";
			this.btnP129.Click += new System.EventHandler(this.btnP129_Click);
			// 
			// btnTest
			// 
			this.btnTest.Location = new System.Drawing.Point(24, 112);
			this.btnTest.Name = "btnTest";
			this.btnTest.Size = new System.Drawing.Size(64, 24);
			this.btnTest.TabIndex = 4;
			this.btnTest.Text = "test";
			this.btnTest.Click += new System.EventHandler(this.btnTest_Click);
			// 
			// label1
			// 
			this.label1.AutoSize = true;
			this.label1.Font = new System.Drawing.Font("宋体", 14.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
			this.label1.Location = new System.Drawing.Point(96, 32);
			this.label1.Name = "label1";
			this.label1.Size = new System.Drawing.Size(163, 25);
			this.label1.TabIndex = 5;
			this.label1.Text = "C#程序设计举例-1";
			// 
			// button1
			// 
			this.button1.Location = new System.Drawing.Point(120, 112);
			this.button1.Name = "button1";
			this.button1.Size = new System.Drawing.Size(80, 24);
			this.button1.TabIndex = 6;
			this.button1.Text = "数组操作";
			this.button1.Click += new System.EventHandler(this.button1_Click);
			// 
			// Form1
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
			this.ClientSize = new System.Drawing.Size(408, 301);
			this.Controls.Add(this.button1);
			this.Controls.Add(this.label1);
			this.Controls.Add(this.btnTest);
			this.Controls.Add(this.btnP129);
			this.Controls.Add(this.btnOpera);
			this.Controls.Add(this.btnP127);
			this.Controls.Add(this.btnT1);
			this.Name = "Form1";
			this.Text = "C#程序设计举例-1";
			this.ResumeLayout(false);

		}
		#endregion

		/// <summary>
		/// 应用程序的主入口点。
		/// </summary>
		[STAThread]
		static void Main() 
		{
			Application.Run(new Form1());
		}



		private void btnT1_Click(object sender, System.EventArgs e)
		{
			/*
			给局部变量 val1 赋值不会影响局部变量 val2,这是因为两个局部变量都是值
			类型(int 类型),每个局部变量都保存着各自的数据。相反,
			赋值 ref2.Value = 123; 则会影响到 ref2,因为 ref1 和 ref2 
			所引用的其实是同一个对象。
			*/
			int val1 = 0;
			int val2 = val1;
			val2 = 123;
			Class1 ref1 = new Class1();
			Class1 ref2 = ref1;
			ref2.Value = 123;
			Console.WriteLine("Values: {0}, {1}", val1, val2);
			Console.WriteLine("Refs: {0}, {1}", ref1.Value, ref2.Value);

		}

		//类(在p127.cs中)成员的用法
		private void btnP127_Click(object sender, System.EventArgs e)
		{
					// Instance constructor usage
					MyClass a = new MyClass();
					MyClass b = new MyClass(123);
					// Constant usage
					Console.WriteLine("MyConst = {0}", MyClass.MyConst);
					// Field usage
					a.MyField++;
					Console.WriteLine("a.MyField = {0}", a.MyField);
					// Method usage
					a.MyMethod();
					// Property usage
					a.MyProperty++;
					Console.WriteLine("a.MyProperty = {0}", a.MyProperty);
					// Indexer usage
					a[3] = a[1] = a[2];
					Console.WriteLine("a[3] = {0}", a[3]);
					// Event usage
					a.MyEvent += new EventHandler(MyHandler);
					//a.MyEvent +=new ChangedEventHandler(MyHandler);
					a.OnEvent();	//触发事件
					// Overloaded operator usage
					MyClass c = a + b;
				}
			static void MyHandler(object sender, System.EventArgs e)
				{
					Console.WriteLine("Test.MyHandler"); 
				}

		private void btnOpera_Click(object sender, System.EventArgs e)
		{
			Complex.Display();
		}

		//委托
		private void btnP129_Click(object sender, System.EventArgs e)
		{
			delegateTest delT = new delegateTest();
			delT.CallDelegate();

			SimpleDelegate ft = new SimpleDelegate(ft2);
			delT.MultiCall(ft,5);
		
		}
		static void ft2() 
		{
			System.Console.WriteLine(System.DateTime.Now.ToString());
			System.Threading.Thread.Sleep(1000);
			
		}

		private void btnTest_Click(object sender, System.EventArgs e)
		{
		/*		int *p;
				int [] intT;
				intT = new int[10];
				intT[5] = 5;
				MessageBox.Show(intT[5].ToString());
				intT = new int[20];
				for (int i=0;i<20;i++) 
					intT[i]=i*2;
				foreach (int i in intT) 
					System.Console.WriteLine(i);
				p=intT;
				System.Console.WriteLine(*(p+1));*/

		}

		private void button1_Click(object sender, System.EventArgs e)
		{
			int intSeed = (int)DateTime.Now.Ticks;  //取随机种子数
			Random r = new Random(intSeed);         //取随机数
			int[] a = new int[20], b = new int[30];
			for (int i = 0; i < 20; i++)
				a[i] = (int)(r.NextDouble() * 120); //赋a: 0--120随机整数
			Console.Write("a={");
			for (int i = 0; i < 20; i++)
				Console.Write("{0} ", a[i]);
			Console.WriteLine("}");
			//复制数组
			a.CopyTo(b, 10);
			Array.Copy(a, b, 10);
			Console.Write("b={");
			for (int i = 0; i < 30; i++)
				if (i == 9) Console.WriteLine();
				else Console.Write("{0} ", b[i]);
			Console.WriteLine("}");
			//排序
			Array.Sort(a);
			Console.Write("a = {");
			for (int i = 0; i < 20; i++)
				Console.Write("{0} ", a[i]);
			Console.WriteLine("}");

			int j = Array.IndexOf(b, a[15]);
			Console.WriteLine();
			Console.WriteLine("Search:{0},posi:{1}",a[15],j);
		}

	}
	class Class1
	{
		public int Value = 0;
	}

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -