bool isAmyGirl = true;
bool isAndyGirl = false;
Console.WriteLine("Is Amy a Girl? {0}", isAmyGirl);
Console.WriteLine("Is Andy a Girl? {0}", isAndyGirl);
Console.ReadLine();
int deposit = -200;
int score = 100;
uint age = 24;
long pixel = 1239847199868777238;
short studentCount = 155;
float height = 155.4F;
double bill = 699.14389713214938513;
decimal cash = 13.138471983741983477466371738123M;
char grade = 'F';
string name = "Kei";
Console.WriteLine("Student Name: {0}.", name);
Console.WriteLine("Grade: {0}", grade);
Console.ReadLine();
寫Main{}的下面
enum grade
{
Outstanding,
ExceedsExpectations,
Acceptable,
Poor,
Dreadful,
Terrible
};
grade myGrade = Program.grade.Acceptable;
grade kerwinGrade = Program.grade.Outstanding;
grade ryanGrade = Program.grade.Terrible;
Console.WriteLine("Mine: {0}", myGrade);
Console.WriteLine("Kerwin's: {0}", kerwinGrade);
Console.WriteLine("Ryan's: {0}", ryanGrade);
Console.ReadLine();
出現錯誤訊息!
const int AGE = 28;
AGE = 40;
可是這樣會出錯!
string gender;
string name;
int age;
Console.Write("請輸入你的性別(M/F): ");
gender = Console.ReadLine();
Console.Write("請輸入你的姓名: ");
name = Console.ReadLine();
Console.Write("請輸入你的年齡:");
age = Console.Read();
Console.WriteLine("姓名:{0}", name);
Console.WriteLine("性別:{0}", gender);
Console.WriteLine("年齡:{0}", age);
Console.ReadLine();
string ageString;
int age;
Console.Write("請輸入你的年齡:");
ageString = Console.ReadLine();
age = int.Parse(ageString);
Console.WriteLine("年齡:{0}", age);
Console.ReadLine();
string ageString;
int age;
Console.Write("請輸入你的年齡:");
ageString = Console.Read();
int.TryParse(ageString, out age);
Console.WriteLine("年齡:{0}", age);
Console.ReadLine();
int cake = 3;
Console.WriteLine("我做了{0}個蛋糕", cake);
Console.WriteLine("每個蛋糕切八片後得到{0}片", cake*8);
Console.WriteLine("但是運送過程中晃壞了3片剩下{0}片", cake*8-3);
Console.WriteLine("剩的蛋糕分給5個人,每個人拿到{0}片,剩下{1}片", (cake*8-3)/5, (cake*8-3)%5);
Console.ReadLine();
int cake = 3;
cake = cake*8;
cake = cake-3;
int eachPerson = cake/5;
int left = cake%5;
int cake = 3;
cake *= 8;
cake -= 3;
int eachPerson = cake/5;
int left = cake%5;
strin name = "Kei";
int age = 24;
float height = 155.4F;
float weight = flaot.MaxValue;
string intro = string.Format("大家好,\n我是{0},\n今年歲{1},\n身高{2},\n體重{3},\n請多多指教!",
name,
age,
height,
weight);
Console.Write(intro);
Console.ReadLine();
strin name = "Kei";
int age = 24;
float height = 155.4F;
float weight = flaot.MaxValue;
string intro = string.Format("大家好,\n我是{0},\n今年歲{1},\n身高{2:F2},\n體重{3:F4},\n請多多指教!",
name,
age,
height,
weight);
Console.Write(intro);
Console.ReadLine();