using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace 第三章
{
class Program
{
enum Mydate //日期枚举
{
Sun = 0,
Mon = 1,
Tue = 2,
Wed = 3,
Thi = 4,
Fri = 5,
Sat = 6
}
class C
{
private int _value;
public int Value
{
get { return _value; }
set { _value = value; }
}
}
static void Main(string[] args)
{
# region 变量的定义赋值
//变量的定义,赋值
int a;
string b;
int c = 0;
string d = "段斌";
//同事定义多个变量并赋值
int e, f, g;
string h, m, k;
string l = "段斌", o = "段斌", n = "段斌";
string p;
//把变量赋值给变量,必须是赋值过的变量
b = l;
#endregion
#region 变量域
//for循环,变量作用域只在循环体内
for (int i = 0; i <= 20; i++)
{
Console.WriteLine(i.ToString());
}
Console.ReadLine();
#endregion
#region 变量的类型
/*
* ----------------------
* 值类型
* ----------------------
*/
int ls = 997;
byte test = 255;
Console.WriteLine("ls={0}", ls);
Console.WriteLine("test={0}", test);
Console.ReadLine();
//强制转换
float fl = 3.14F;
double db = 3.14;
double dbTest = 32d;
fl = (float)db;
bool tr = true;
/*
* ----------------------
* 引用类型
* ----------------------
*/
int v1 = 0;
int v2 = v1;
v2 = 927;
C r1 = new C();
C r2 = r1;
//C r2 = new C();
r2.Value = 112;
Console.WriteLine("Value:{0},{1}", v1, v2);
Console.WriteLine("Refs:{0},{1}", r1.Value, r2.Value);
Console.ReadLine();
#endregion
#region 枚举的使用
int toDay = (int)DateTime.Now.DayOfWeek; //获取星期几
switch (toDay)
{
case (int)Mydate.Sun:
{
Console.WriteLine("今天星期日");
break;
}
case (int)Mydate.Mon:
{
Console.WriteLine("今天星期一");
break;
}
case (int)Mydate.Tue:
{
Console.WriteLine("今天星期二");
break;
}
case (int)Mydate.Wed:
{
Console.WriteLine("今天星期三");
break;
}
case (int)Mydate.Thi:
{
Console.WriteLine("今天星期四");
break;
}
case (int)Mydate.Fri:
{
Console.WriteLine("今天星期五");
break;
}
case (int)Mydate.Sat:
{
Console.WriteLine("今天星期六");
break;
}
default:
{
break;
}
}
Console.ReadLine();
#endregion
#region 数据类型转换
double x = 19810927.8112;
int y = (int)x;//强制显式转换
int zhuanB = 312;
double zhuanD = zhuanB; //隐式转换
Console.WriteLine(y);
Console.ReadLine();
//装箱,值类型隐式转换为引用类型
int zhuanI = 2008;
object obj = zhuanI;
Console.WriteLine("1 zhuanI的值为{0},装箱后的对象为{1}", zhuanI, obj);//2008,2008
zhuanI = 927;
Console.WriteLine("2 zhuanI的值为{0},装箱后的对象为{1}", zhuanI, obj);//927,2008
//拆箱,引用类型强制转换为值类型
int zhuanX=(int)obj;
Console.WriteLine("拆箱 :对象为:{0},值为{1}",obj,zhuanX);
Console.ReadLine();
#endregion
#region 常量的使用
const double doublePI=3.1415926;//常量必须初始化赋值,不可修改
Console.WriteLine(doublePI) ;
#endregion
}
}
}
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace 第三章
{
class Program
{
enum Mydate //日期枚举
{
Sun = 0,
Mon = 1,
Tue = 2,
Wed = 3,
Thi = 4,
Fri = 5,
Sat = 6
}
class C
{
private int _value;
public int Value
{
get { return _value; }
set { _value = value; }
}
}
static void Main(string[] args)
{
# region 变量的定义赋值
//变量的定义,赋值
int a;
string b;
int c = 0;
string d = "段斌";
//同事定义多个变量并赋值
int e, f, g;
string h, m, k;
string l = "段斌", o = "段斌", n = "段斌";
string p;
//把变量赋值给变量,必须是赋值过的变量
b = l;
#endregion
#region 变量域
//for循环,变量作用域只在循环体内
for (int i = 0; i <= 20; i++)
{
Console.WriteLine(i.ToString());
}
Console.ReadLine();
#endregion
#region 变量的类型
/*
* ----------------------
* 值类型
* ----------------------
*/
int ls = 997;
byte test = 255;
Console.WriteLine("ls={0}", ls);
Console.WriteLine("test={0}", test);
Console.ReadLine();
//强制转换
float fl = 3.14F;
double db = 3.14;
double dbTest = 32d;
fl = (float)db;
bool tr = true;
/*
* ----------------------
* 引用类型
* ----------------------
*/
int v1 = 0;
int v2 = v1;
v2 = 927;
C r1 = new C();
C r2 = r1;
//C r2 = new C();
r2.Value = 112;
Console.WriteLine("Value:{0},{1}", v1, v2);
Console.WriteLine("Refs:{0},{1}", r1.Value, r2.Value);
Console.ReadLine();
#endregion
#region 枚举的使用
int toDay = (int)DateTime.Now.DayOfWeek; //获取星期几
switch (toDay)
{
case (int)Mydate.Sun:
{
Console.WriteLine("今天星期日");
break;
}
case (int)Mydate.Mon:
{
Console.WriteLine("今天星期一");
break;
}
case (int)Mydate.Tue:
{
Console.WriteLine("今天星期二");
break;
}
case (int)Mydate.Wed:
{
Console.WriteLine("今天星期三");
break;
}
case (int)Mydate.Thi:
{
Console.WriteLine("今天星期四");
break;
}
case (int)Mydate.Fri:
{
Console.WriteLine("今天星期五");
break;
}
case (int)Mydate.Sat:
{
Console.WriteLine("今天星期六");
break;
}
default:
{
break;
}
}
Console.ReadLine();
#endregion
#region 数据类型转换
double x = 19810927.8112;
int y = (int)x;//强制显式转换
int zhuanB = 312;
double zhuanD = zhuanB; //隐式转换
Console.WriteLine(y);
Console.ReadLine();
//装箱,值类型隐式转换为引用类型
int zhuanI = 2008;
object obj = zhuanI;
Console.WriteLine("1 zhuanI的值为{0},装箱后的对象为{1}", zhuanI, obj);//2008,2008
zhuanI = 927;
Console.WriteLine("2 zhuanI的值为{0},装箱后的对象为{1}", zhuanI, obj);//927,2008
//拆箱,引用类型强制转换为值类型
int zhuanX=(int)obj;
Console.WriteLine("拆箱 :对象为:{0},值为{1}",obj,zhuanX);
Console.ReadLine();
#endregion
#region 常量的使用
const double doublePI=3.1415926;//常量必须初始化赋值,不可修改
Console.WriteLine(doublePI) ;
#endregion
}
}
}