数据类型详解
——预定义值类型与用户定义值类型
namespace ConsoleApp3
{
class Program
{
static void Main(string[] args)
{
//1.布尔bool -> System.boolean
//double score = 75.5;
//bool passing = false;
//Console.WriteLine(passing);
//passing = score > 60;
//Console.WriteLine(passing);
//Console.ReadLine();
//2.字符型 char->System.Char
//char c = 'e';
//Console.WriteLine(c);
//Console.WriteLine((int)c);
//Console.ReadLine();
//char c1 = '\x004b';
//Console.WriteLine(c1);
//Console.WriteLine((int)c1);
//Console.ReadLine();
//short x = 75;
//char y = (char)x;
//Console.WriteLine(y);
//Console.ReadLine();
//3.整型 int ->System.Int32
//int x = -50;
//int y = Int32.MaxValue;
//Console.WriteLine(y);
//Console.ReadLine();
//uint z = -5555;
//4.浮点数
float f = 3.14f;
double d = 3.14;
decimal dec = 3.14m;
Console.WriteLine(f);
Console.WriteLine(d);
Console.WriteLine(dec);
Console.ReadLine();
decimal dec1 = Decimal.Add(dec, dec);
Console.WriteLine(dec1);
Console.ReadLine();
//用户自定义值类型
//1.枚举
string name = "张三";
int age = 20;
//string gender = "男";
Gender gender = Gender.男;
Department dep = Department.营业部;
Console.WriteLine("姓名:{0},年龄:{1},性别:{2},部门:{3}", name, age, gender,dep);
Console.ReadLine();
//2.结构
Department_1 department = new Department_1();
department.name = "市场部";
department.tel = "010-12345678";
department.leader = "李四";
Console.WriteLine("姓名:{0},年龄:{1},性别:{2},部门:{3}", name, age, gender, department.name);
Console.ReadLine();
//3.练习:
//(1)要求打印出下信息“这本书的名字是:C#程序设计,作者是:ROSE,作者性别是:女,售价是:56.8,出版社是:人民邮电出版社.”
//要求用到“结构”和“枚举”
BookInfo book = new BookInfo();
book.bookName = "C#程序设计";
book.bookAuthor = "ROSE";
book.authorGender = Gender.女;
book.bookPrice = 56.8m;
book.pCompany = "人民邮电出版社";
Console.WriteLine("这本书的名字是:{0},作者是:{1},作者性别是:{2},售价是:{3},出版社是:{4}.", book.bookName,book.bookAuthor,book.authorGender,book.bookPrice,book.pCompany);
Console.ReadLine();
//(2)要求打印出下信息“学生信息如下,姓名:MIKE, 年龄:16,性别:男,身高:180cm,数学:135,语文:118,英语:130,C语言:94,总分:477”
//要求用到“结构”和“枚举”
Student stu = new Student();
stu.name = "MIKE";
stu.age = 17;
stu.stuGender = Gender.男;
stu.stature = 180;
stu.china = 118;
stu.maths = 135;
stu.english = 130;
stu.c = 94;
int total = stu.c + stu.china + stu.english + stu.maths;
Console.WriteLine("学生信息如下,姓名:{0}, 年龄:{1},性别:{2},身高:{3}cm,数学:{4},语文:{5},英语:{6},C语言:{7},总分:{8}。",stu.name,stu.age,stu.stuGender,stu.stature,stu.maths,stu.china,stu.english,stu.c,total);
Console.ReadLine();
}
}
//public enum Gender
//{
// 男,
// 女
//}
public enum Gender
{
男=1,
女=2
}
public enum Department
{
市场部,
财务部,
行政部,
营业部
}
public struct Department_1
{
public string name;
public string tel;
public string leader;
}
public struct BookInfo
{
public string bookName;
public string bookAuthor;
public Gender authorGender;
public decimal bookPrice;
public string pCompany;
}
public struct Student
{
public string name;
public int age;
public Gender stuGender;
public int stature;
public int china;
public int maths;
public int english;
public int c;
}
}