- Naming variables: a letter, underscore, @ start can be followed by alphanumeric characters and underscores
Note: Do not use a variable in C # keyword, blue font is key
- The two big variable naming rules:
pascal case: an identifier in each word capitalized
camel case: in addition to the first word identifier all words are capitalized
Users receive the content revenue in the C # code:
//输入如姓名
Console.WriteLine("您好,请输入您的名字:");
string stuName = Console.ReadLine();
Console.ReadKey();
//输入年龄
Console.WriteLine("您好,请输入您的年龄:");
string stuAge = Console.ReadLine();
Console.ReadKey();
Console.WriteLine("您好,请输入您的性别:");
string stuSex = Console.ReadLine();
Console.ReadKey();
//综合:
onsole.WriteLine("您的姓名的:" + stuName + "您的年龄是:" + stuAge + "您的别是:" +stuSex);
Escape: In front of the double quotes slash \ + this special character, you can put this particular character shows up
\n | Newline |
\b | It denotes a cover, if \ b back something, then cover \ b in front of a word |
\t | Represents alignment (horizontal tab) |
\\ | It represents a slash |
@ | He said they did not escape, like a realization address, this time you can add an @ in front @ Symbol has two functions in C # Action 1, preceded by the string representation @ string unescape E.g. string path = @ "d: \ root \ subdir"; 2 action, if a user-defined object name and system conflicts keywords can be added in front of the variable @ 例如 string @Class="this is a test";
|
- Auto Switch:
Involved in computing (arithmetic and assignment operator) of the operands and results must be the same type
What is implicit conversion:
For example, there is a variable of type int, but it is obtained by addition, subtraction, it is necessary to consider the calculation display conversion, in addition to the operation needs to be converted float or double, int and then cast the result;
1. implicit type conversion
called implicit conversion, conversion is the system default, which is essentially a small memory capacity is automatically converted to the data type Data type large storage capacity
2. Explicit type conversion
Explicit type conversion, i.e. cast. In contrast with the implicit conversion, and cast cause data loss.
Cast operator (int)
double aum = 20.44;
int ave= (int)aum;
Placeholders: {0}
console.WriteLine(“美女你喜欢吃什么水果”);
String str=console.readLine();
Conosle.WriteLine("哈哈,这么巧,我也喜欢吃{0}“,str);
Console.ReadKey();
Conosle.WriteLine("哈哈,这么巧,我也喜欢吃{0}{1}“,str,ave);
//可以同时显示俩个占位符
//如果让占位符有格式: {1:0.00} 会有四舍五入
Type conversion:
Convert is no longer just a memory level conversion, but consider the significance of the data conversion.
To convert by Convert.ToInt32 (can be converted to an int data) other types of data into an int
例子:
//把字符串类型的数字转换成 整形 。
String Ave=“234234”;
Int chinese=convert.toint32(strchinese);
想转换成什么类型就 to 什么类型
Conver.tochar
Arithmetic operators and compound assignment operator:
Operator:
Arithmetic operators | ||
++ | Self plus one, plus front and rear plus | |
-- | A decrement, a front and a rear Save Save | |
Composite Operators | ||
+= -= *= /= %= |
After addition / subtraction | ++ add itself does not participate in the operation of a // int mum = 100; mum++; Console.WriteLine ( "mum values:" + mum); Console.ReadKey();
Results shown are: MUM value: 101 // If after participating in the operation ++, mum's first original value accumulation, and finally own a plus int mum = 100; mum=mum++; Console.WriteLine ( "mum values:" + mum); Console.ReadKey(); The results show that: a value of 100 mum |
Before the addition / subtraction before | // do not participate in operations before ++ or before - itself a plus or minus one int mum = 100; --mum; Console.WriteLine ( "mum values:" + mum); Console.ReadKey();
Results shown are: MUM values: 99 // first the operations involved in pre ++ -, add to their participation in a calculation or decremented by 100 MUM = int; |
Before and after comparison: | If the individual concerned ++ mum and mum ++ final result is the same
But int number = ++ mum +10 // 110 results And int number = 10 + mum ++ // 100 results The end result involved in computing is not the same If the individual concerned ++ mum and mum ++ final result is the same
|
Mixing assignment operator | += -= *= %= Number = number +10 Number += 10 Although the wording is different but the effect is the same as the ultimate realization |
Relational operators: | > < == != >= <= |
逻辑运算符 | && || ! |
举个栗子:
static void Main(string[] args)
{
//让用户输入老苏的语文和数学成绩,输出一下判断是否正确
//正确输出true,错误输出false
//1. 老苏的语文和数学成绩都大于90分:
Console.WriteLine("请输入老苏的语文成绩:");
string ChinGrade;
ChinGrade= Console.ReadLine(); //获得语文成绩;
Console.WriteLine("请输入老苏的数学成绩:");
string MantGrade;
MantGrade = Console.ReadLine();
//判断老苏的语文和数学成绩是否都大于90 分
bool result;
result=Convert.ToInt32 (ChinGrade) > 90 && Convert.ToInt32(MantGrade) > 90;
Console.WriteLine("老苏的最终{0}全部高于90分",result); // 利用一个占位符;
Console.ReadKey();
}