Csharp实例编程百例.rar
源代码在线查看: class1.cs
using System;
namespace CValueApp
{
///
/// Class1 的摘要说明。
///
class Class1
{
///
/// 应用程序的主入口点。
///
[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;
}
}
}
}