String
char
Set of string name = "John Doe";
double quotes, char
single quotes string
are immutable and can not be changed after once initialized, each of the existing string
post-operation, in fact created a new string
, and then assigns the new value of this variable, the old the value is to clean up the framework
This 新建 赋值 清理旧值
process is repeated 10,000 times, not smart enough, recommendedStringBuilder
Use the StringBuilder Append method can be used to extend the string, this efficiency should be higher than that of some
string operator
+ connecting two or more of the string (and then can put another type ToString +)
the Format python with the same format form, and leave the original data type, line {}
Length Gets the string length
SubString get string
IndexOf find the first index of a character
Replace to replace
Contains contains a character or string
StartsWith start with what
Endswith to what end
\ Escape character meaning is not to say that the universe GM
@ If you think \ is not intuitive use too much, you can string the whole front of the @ symbol, which is what this string is valid and will not be escaped, see The following figure
Data & Time
Default: date + time
formatting when m represents minute, M represents the month
Time cultural differences lead to different areas of the display can be set up System.Globalization.CultureInfo
to solve
Parse and TryParse
the latter not being given time to resolve, more Insurance
Null null type
Normal data type can not be assigned to null, int a = null ;
so that the compiler will complain of
is to add a question mark after the data type, ?
so that this amount can be assigned null
(can be assigned to null
, and not have to give him an assignment to null
)
assigned to the null value in the new course can be assigned to himnullable = 123;
And the above if
comparison, two were determined, and has a value of 42, the output It‘s 42!
following the GetValueOrDefault
method, has the value returns the value is null
returned to its default value of the base type ( int
the default value is 0) is more compact than the above use
var keyword
We can put one on the left of a variable var
to implicitly define its data type
The above int
is an explicit definition of
the following name
is an implicit definition does not explicitly say that string
the compiler to look at your name
assignment is string
, he took name
defined as string
the
this display and is defined as fast, do not worry about what's on efficiency difference
var
Can only be used in method
years, it can not be used at class
levels in
Sometimes we have to simplify the code on the use of var
, or directly with the return value of the function as the type of the variable (I do not control what type of return, I var result = someMethod()
will do)
The figure, a var
let's play a little keyboard letter how much you have to say to copy and paste one line modification I have no idea. . . .
In most cases, we can put var
into some kind of fixed type, but in an anonymous type ( anonymous types
have to use), the revisit this later.