class1.cs

来自「Csharp实例编程百例.rar」· CS 代码 · 共 71 行

CS
71
字号
using System;

namespace CValueApp
{
	/// <summary>
	/// Class1 的摘要说明。
	/// </summary>
	class Class1
	{
		/// <summary>
		/// 应用程序的主入口点。
		/// </summary>
		[STAThread]
		static void Main(string[] args)
		{
			//
			// TODO: 在此处添加代码以启动应用程序
			//
			
			//值类型定义及初始化
			System.Int16 aShort = new System.Int16 ();//System.Int16 等同与 short关键字
			byte aByte = new Byte ();
			decimal aDecimal = 100.5m;
			char aChar = 'y';
			Console.WriteLine ("值类型的初始化值:{0} ,{1} ,{2} ,{3}",aShort,aByte,aDecimal,aChar);

			//值类型的赋值与操作
			float aFloat = 123.123F;
			bool aBool = ((aFloat > 121) && (aFloat < 125));
			if (aBool)	{
				int aInteger;
				aInteger = (int) aFloat;//显示转换

				double aDouble;
				aDouble = aFloat;		//隐式转换

				Console.WriteLine ("类型转换结果:{0} ,{1}",aInteger,aDouble);
			}
			
			//枚举类型的使用
			long x = (long)Data.Min ;
			long y = (long)Data.Max ;
			Console.WriteLine ("枚举类型的值:{0} ,{1}",x,y);

			//结构的使用
			MyPoint aPoint;
			aPoint.x = 10;
			aPoint.y = 100;
			Console.WriteLine ("结构类型的值:{0} ,{1}",aPoint.x ,aPoint.y );
			

		}

		//枚举类型的定义
		enum Data : long {			
			Min = 255L, Mid = 1024L, Max = 32768L
		};

		//结构的定义
		public struct MyPoint
		{
			public int x, y;
			public MyPoint( int x, int y)
			{
				this.x = x; 
				this.y = y;
			}
		}
	}
}

⌨️ 快捷键说明

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