Home > Article > Backend Development > Summary of the classic learning stages for getting started with C# (messy)
CLR: common language runtime (.net common language runtime) manages the execution of all applications developed by the .net library
CTS: common type system (common type system) specifies the most basic type Conducive to interoperability between various languages using the .NET Framework
CIL: common intermediate language (common intermediate language) compiles the code into this language. The CIL code is independent of the computer, os, and cpu, and is compiled by the JIT compiler Use the native code required to create
JIT: just in time (CIL code is only compiled when needed)
Managed code: Compile the code to CIL, store it in an assembly, and then use the JIT compiler to It compiles to the code required by the native machine and also manages the execution of code written in the .NET Framework.
Steps required to create a .NET application:
->Write the application code using C
#->Compile the code to CIL and store it in the assembly
-> When executing code, the code must be compiled to native code using a JIT compiler -> Running native code in a managed CLR environment
String insertion: such as outputting Console.WriteLine($"{outline}") ;
Operator precedence: , -- used as prefix, (), , - when unary,! ,~
*,/,%
,-
<<,>>
<,>,<=,>=
==,! =
&
^
|
&&
||
=,*=,/=,%=, =,-=,<<=,>> ;=,&=,^=,|=
,--Branch technology used as suffix
switch statement can be used in C Run another case after running one case statement, but this is illegal in C#. Each case statement requires a break to interrupt switch execution
In addition, you can use the return statement to not only interrupt the switch structure, but also interrupt the current function. Execution; you can also use goto statements
Three types of loops: do loop, while loop, for loop
Interrupt commands for loops: break, continue, return
Enumeration: Converting enumeration values to other types requires explicit conversion Use replace("str1", "str2") to replace the function and use str2 to replace all str1 in the string
Or use the output parameter out keyword, you can use unassigned variables. When the function uses out, it must be regarded as not yet assigned.
static keyword defines global variables, const defines global constants
Delegate: a type that stores function references, does not With a function body, use the delegate keyword, and the delegate declaration specifies a return type and a parameter list
The class determines the properties and behaviors that the object will have.
class progrem
{ //You can write fields, functions, properties, and constructors. .
//Field: Store data Attribute: Protect field get set (instantiation is required when protecting automatic attributes) Function: Describe the behavior of the object Constructor: Initialize the object and assign a value to each attribute of the object
}
Chuanzhi Podcast Basic Strengthening 1:
oop:
Encapsulation:
--->Reduce a lot of redundant code
--->Encapsulation will make it difficult to understand The functions are encapsulated, but a very simple interface is provided to the outside world. We will use it OK.
having Class
2. If the parent class is equipped with a sub-class object, you can convert this parent class to the corresponding sub-class object
---- & gt; Keyword
1, IS: Back to Bool Type, indicating whether this conversion can be done
2. as: If the conversion is successful, the object is returned, otherwise null is returned
Function: We can treat all subclasses as parent classes, and perform operations on the parent class Programming, writing universal code, adapts to changing needs.
Polymorphism:
--->Virtual method
interface
Keywords
new
1. Create an object
--->Create space in the heap (the object is a reference type, and the values of the reference type are all in the heap)
--> Create an object in the opened heap space This
1. Represents the object of the current class
2. The display of the display of its own structure
1. Show the constructor that calls the parent class (not the object of the parent)
2. Calling members of the parent class
The static constructor can only be executed under the following circumstances:
* When creating a class instance that contains a static constructor
* Accessing the static class of a class that contains a static constructor When members are
string and object are simple reference types, arrays are implicit reference types, and every class created is a reference type
The compiler does not allow derived classes to be more accessible than the base kind.
The specification of the interface must be placed after the base class inheritance and separated by commas.
The interface does not have the keywords abstract and sealed (they do not contain implementation code, cannot be instantiated directly, and must be inheritable). The interface is not a class, so it does not inherit the methods contained in System.Object
Equals() bool
ReferenceEquals() bool: Compare the two objects passed to it to see if they are the same A reference to an instance
ToString() String: Returns the string corresponding to the object instance
GetType() System.Type : Returns the object type (typeof operator: can convert the class name into a System.Type object)
GetHashCode() int: Returns a value representing the object status in compressed form
Constructor initializer, which puts the code after the colon of the method definition. For example, you can specify the base class constructor to use in the constructor definition of the derived class.
Use the base() keyword to specify the .NET instantiation process. Use the constructor with specified parameters in the base class.
Define a class that cannot be created: define it as a static class, or make all its constructors Functions are defined as private.
Classes that cannot be created can be used through the static members they possess.
For the ArrayList collection, use the Add() method of the object to add new items;
yield iteration
Boxing is to convert the value type to the System.Object type, or convert Is an interface type implemented by a value type. Unboxing is the opposite.
Function: It allows the use of value types in collections whose item type is object. Secondly, there is an internal mechanism that allows the object method to be called on the value type.
is operator:
You cannot overload assignment operators, such as =, nor can you overload && and ||
IComparable is implemented in the class of the object to be compared, and you can compare this object with another object: Provides CompareTo(), int, accepts an object
IComparer is implemented in a separate class and can compare any two objects: Provides Compare(), int, accepts two objects
Class Comparer provides the ICompare interface Default implementation: Comparer.Default.Compare(one,two). CaseInsensitiveComparer class: case-insensitive
Declare nullable types: int? nullableInt; int? is the abbreviation of System.Nullable
Null coalescing operator?? With the empty conditional operator?. you can set a default value when the result is null:
int? count=customer.order?.Count() ?? 0;
In addition, another use of the empty conditional operator is a triggering event.
Covariance, anti-variance:
Generic type parameters are defined as covariant, add the out keyword, otherwise, use the in keyword for anti-variability
Chuanzhi Podcast:
1. Import the namespace
The namespace is the "folder" of the class. Classes are files in a "folder". Need to import the namespace
Add a reference:
If I need to access a class in another project in one project
--->Add a reference to another project
-- ->Import namespace
2. Static and non-static
Static members: modified by static
Instance members: not modified by static
Static members are loaded into memory before instance members. Only when the object is created can Instance members.
Only static members can exist in a static class
Calling:
Static member calling:
Class name. Static member name;
Instance member calling:
Instance name.Instance member;( The instance is our object)
When to use static?
---->As a tool class, such as all extension methods! All require static
---->Resources are shared throughout the project. Just because it is resource shared, static members must wait until the entire project is over
before resources are released.
We should use static members as little as possible in our projects.
Inheritance is the process of creating objects.
3. Design pattern
---->Single case design pattern
Throughout the program, we must ensure that the object must be unique.
---->Step 3: Declare a static function to return a globally unique object
Example:
//Step 1: Constructor privatization
## InitializeComponent();
}
// use using use using using Objects
Public Static Form2 Getsingle ()
{
if (_SINGLE == NULL)
{
_SINGLE = New Form2 ();
Return _SINGLE;
}
Simple Factory Design Pattern
## Re-enter the operator: return a calculated parent class and call the method to get the result.
Add Sub Cheng Chu
The construction industry was the first to apply the concept of design pattern
1. Register a company
2. Recruit troops
3. Bid to buy land
4. Arrange The construction team started construction
5. Selling the building
Design patterns are used to specifically solve some specific problems.
4. Class library
.dll file, we use class library to help us encapsulate some common functions
5. Value type and reference type
Value type: int double char bool decimal struct enum
Reference type: string array custom class interface delegate
Value type values are stored on the memory stack, and reference type values are stored in the heap.
The efficiency of storing data on the stack is higher than that on the heap.
Value Pass: Pass the value type as a parameter and pass the value itself.
Note:
REF can change the value to the reference transfer.
Passing by reference: Passing reference type values as parameters, what is passed is a reference.
6. String learning
Important features:
Immutability, no matter what operations we do on the string, a new instance will be generated in the memory.
Resident pool
We can regard a string as a read-only array of type char.
GC:Garbage Collection, every once in a while, will scan the entire memory and find out if some space is not pointed to. then destroy it immediately.
1. Explain the immutability of strings 2. The "temporary pool" feature of string constants.
String string, a string can be regarded as a character array, immutable (modify the elements in the string through a for loop, fail!).
Attribute
Length //Get the number of characters in the string. "aA我你他"→5
Method
IsNullOrEmpty() Static method, judged to be null or "" (static method)
ToCharArray() Convert string to char[]
ToLower( ) Lowercase, must receive return value. (Because: string is immutable);
ToUpper() uppercase.
Equals() Compares whether two strings (address/object state, and == compares object references) are the same. Ignore the comparison of upper and lower case, StringComparation.
to be compared to the string type, regardless of the equal sign or Equals are all compared to the value itself.
//Equals compares addresses by default, but if we use Equals in a class that we define, we will rewrite Equals so that it can be compared according to our own needs
The corresponding data returns -1. //Interview question: Count the number of times "Tiananmen" appears in a string.
LastIndexOf() If the corresponding data is not found, return -1
Substring() // 2 overloads, intercept the string.
Split() //Split the string.
Join() Static method
Replace()
Object initializer: Use non-default constructor/no need to add additional code, use key-value pairs for each property to provide its value .
Merge objects and collection initializers (suitable for use with LINQ technology) (the compiler calls the Add() method of the collection for each item provided in the collection initializer)
var keyword, implicit Formula inference variable type, which can be int, string, array (numeric values are never interpreted as nullable types, unless new int?[] is defined), etc.
If you want to modify attributes in the data storage object value, you cannot use anonymous types (because they are defined as read-only properties)
dynamic keyword, dynamic variable type,
optional parameters, parameters without default values cannot be placed with default values after the value parameter.
Named parameters, the order of parameters is arbitrary and optional. But if you mix named and positional parameters, you must include all positional parameters, followed by the named parameters.
Lambda expression: is a delegate, assigned to a variable of delegate type; interpreted as an expression tree
Performance: Parameter list in parentheses => C# statement/{Multiple lines of code if not yet For void delegation, you need to add return}
The LINQ framework contains a generic class that can be used to encapsulate Lambda expressions. One way to use this class is to extract the Lambda expression written in C# and convert it into the corresponding SQL Script
Extension method Aggregate() means applying an accumulator function to each pair of elements from the beginning to the end of the collection.
Chuanzhi Podcast Basic Strengthening 3:
1. StringBuilder: A tool for performing large-scale string operations. String objects are immutable.
Convert StringBuilder to String using ToString();
It is just a tool for splicing strings, most of them will also be converted to String
*StringBuilder sb=new StringBuilder();
*sb.Append( );//Append string
*sb.ToString();//ToString("x2"), which means converting to hexadecimal and is two digits.
*sb.Insert();
*sb.Replace();
Use a program to splice tables in html: There is no DocumentText for form applications in WPF, and you can only use webBrow.NavigateToString(sb. ToString());
2. out: The out parameter focuses on returning multiple values in the function; the parameter requirement must be assigned a value inside the method
3. Ref parameter: The ref parameter focuses on bringing a value Make changes in the Australian function, and then bring out the changed values. The ref parameter does not need to be assigned a value within the function, and the ref parameter must be assigned a value outside the function
4.
5. Collection learning:
Non-generic collection:
ArrayList
Generics Collection:
List
Capcity: The number of elements that can be included in the collection (the initial value is 4, doubled each time)
Count: Get the set The number of elements actually contained in
Add(): Add a single element use use use use use use use use out through out through using using using out out through ’s ‐ through out through out through through through through‐ ‐ ‐‐ ‐‐ ‐ - to
’ ’ ’ s ’ s ’ s ’ s ’ s ’ s ’ s ‐ ‐ ‐ ‐ ’ : Remove the element
Removerange (): Remove the element within a certain range
Toarray (): The collection is converted into an array
Tolist (): ;Tkey,Tvalue>
6. Packing and unboxing:
Packing: value type--->Reference type
Unboxing: reference type--->Value type
We To determine whether unboxing or boxing has occurred, you must first determine whether there is an inheritance relationship between the two data types.
In the box, what type of box is used, and what types are removed when disassembling.
7. Encoding format:
ascii 256
6000 GB2312
GBK GB18030
ISO
Unicode
utf-16
utf-8
The reason for the garbled code: the encoding and opening used when we save this file The encoding format used in this file is inconsistent.
# . Move(): cut Cut
Copy(): copy
Delete():
ReadAllLines() ReadAllText() The default encoding format used by ReadAllText() is utf-8
Directory: The operation is the folder
CreateDirectory: Create a new folder
Delete:Delete
Move:Cut
Exist() determines whether the specified folder exists
GetFiles() Gets the full path of all files in the specified directory
Directory.getFiles (@"e: \ download", "*.avi") Get all .avi file
stetDirectories () to get all the folders in the specified directory
The folder
Regular expression main class: Regex
is a template. We can use this template to find the data we want in a bunch of strings.
Note: Regular expressions operate on strings.
Composition:
Qualifiers, metacharacters, commonly used expressions
Determine whether to match: Regex.IsMatch("String", "Regular Expression");
String extraction: Regex. Match("String", "Regular expression of the string to be extracted");
(Loop to extract all): Regex.Matches()
String replacement: Regex.Replace("String", "Regular", "Replace content");
. ? Match a large number of characters
(? .11111."
Greed: . . Match as many as possible
Non-greedy: .? . Match as few as possible, 1
Style: Set certain properties to be applied to the control in batches
Template: Set the control appearance based on it
Trigger:
To define the properties monitored by the Trigger object, you should use the Trigger.Property property
To define when the Trigger object is activated, you should set the Trigger.Value property
Animation: Created through storyboards, storyboard objects are included in the resource dictionary and must be identified through the x:Key attribute
Timeline without keyframes: DoubleAnimation, PointAnimation Dependent properties with ColorAnimation
: Enter propdp and press the Tab key twice to insert the property template
XML: Extensible Markup Language
Difference from HTML: Elements in XML must be closed! Attributes of elements in XML must be quoted
Syntax specifications: Tag, Nest, and Attributes.
The label (i.e. Element) must be closed, the attribute value must be surrounded by "", and labels can be nested within each other.
In XML, a node (Node) contains an element (Element).
Case sensitive
Create XML: DOM Document Object Model
XmlDocument doc=new XMLDocument();
## .RemoveAll(); Yes, remove all child nodes under the root node
Delete child nodes: ITems.RemoveChild(xn);
Delete the attribute value of a node: xn.Attributes.RemoveNamedItem("Count") ;
ctrl K and S/X, shortcut keys to insert code segments/outer code, such as #region
Delegation delegate: use a delegate to pass a function as a parameter
DelSayHi del = SayHiChinese;//new DelSayHi(SayHiChinese);
Comparison: Delegation is unsafe, The event itself is a safe delegate
Define the event:
public delegate void delTest(); //A delegate is required when registering the event
public event delTest eventTest; //No parentheses
eventTest = new delTest(method1);
eventTest = new delTest(method2);
Summary:
Role of delegation:
Place a placeholder, if you don’t know what will happen in the future When executing the specific code of the method, you can first use a delegate variable to replace the method call (the return value and parameter list of the delegate must be determined)
Function of the event:
The function of the event is the same as the delegate variable, but in terms of function More restrictive than delegate variables.
For example: 1. Methods can only be bound through = or -=, 2. Events can only be called (triggered) within the class.
Benefits of assemblies:
Only necessary assemblies are referenced in the program, reducing the size of the program;
Assemblies can encapsulate some code and provide only necessary access interfaces.
Chapter 16:
Cloud: It is just a large amount of commercial computer hardware running in a data center. This data center can run programs and store large amounts of data.
Cloud service model:
1. Infrastructure As a Service (IaaS): Responsibility starts from the operating system and goes up.
2. Platform as a Service (PaaS): The value is responsible for the programs and their dependencies that run on the selected operating system.
3. Software as a Service (SaaS): A software program or service used on a device accessed through the Internet.
Related recommendations:
Look at C, C, C#, Java through static local variables, Features of PHP
The above is the detailed content of Summary of the classic learning stages for getting started with C# (messy). For more information, please follow other related articles on the PHP Chinese website!