Basic notes 1

Source: Internet
Author: User
Tags string methods

♠Code specifications

Camel naming: lowercase for the first word and userpassword for the first letter (common variables, local variables, fields)

Pascal's naming method: each word is capitalized with getname () (method name, attribute, class name)

.Csfile can be opened through the csc.exe program. When the program is running, it uses the JIT compilation (just in time) to instantly compile the Assembly into a machine code that can be understood by the CPU. Then, the CPU can execute

Object-oriented

Object-Oriented Programming (OOP → object-oriented programming)

OOA: object-oriented analysis object-oriented analysis

OOD: object-oriented design object-oriented design,

Ood OOAD: object-oriented analysis and design object orient Analysis Design

Object-oriented features: encapsulation, inheritance, and polymorphism. My understanding is that this is all for enhanced code reuse and program scalability.

Class: A class is a model. Determining the features (attributes) and behavior (methods) objects that an object will possess is a specific entity that you can see and feel-everything is an object.

Classes are abstract, while objects are instances of classes.

In a class, data is used to indicate the state of a thing, and functions are used to implement the behavior of a thing.

Attributes encapsulate fields and inherit (the relationship between classes .)

All classes are directly or indirectly inherited from objects.

The role of polymorphism: Different subclass objects are treated as parent classes, which can shield the differences between different subclass objects, write common code, and make common programming to adapt to the changing needs.

Notes for Virtual Methods:

1. If a method in the parent class needs to be overwritten by the subclass, you can mark this method as virtual

2. Virtual methods must be implemented in the parent class, even if they are empty implementations.

3. The virtual method subclass can be overwritten or not overwritten.

Notes for abstract methods:

1. You need to mark it with abstract keywords.

2. abstract methods cannot be implemented in any way.

3. Abstract members must be included in abstract classes.

4. Since abstract members are not implemented, the Child class must overwrite the abstract members.

5. abstract classes cannot be instantiated. The role of abstract classes is to inherit them.

6. abstract classes can include abstract members and members with specific code.

7. There are also abstract methods that cannot be modified using static

Note:

1. interfaces can only contain methods (attributes, events, and indexers are all methods)

2. Members in the interface cannot have any implementations.

3. The interface cannot be instantiated.

4. The interface members cannot have any access modifiers. (Public by default)

5. The subclass that implements the interface must implement all the members of the interface.

6. When subclasses implement interface methods, they can be directly implemented without any keywords.

7. The interface has the significance of polymorphism.

Methods that implement polymorphism include abstraction, virtual methods, and interfaces.

Give priority to the interface and then abstract the final virtual Method

When to use abstract classes and virtual methods?

Check whether this class needs to be instantiated in the future. If it needs to be instantiated, it cannot be abstract;

 

Five access Modifiers

PRIVATE: the default access modifier of the current class.

The current class and subclass of protected can be accessed (used in inheritance .)

Internal can be accessed inside the current Assembly

Protected internal in the current Assembly or subclass (different assembly can also be accessed ).

Public anywhere

Static class

Static classes cannot be inherited by other classes, and static members cannot be inherited (the same class is accessed)

Static classes can only inherit from object classes. (Static classes cannot inherit from other classes .)

Static classes cannot implement any interface (because all the members in the interface are instance members .)

Sealed :() the sealed class cannot be inherited.

The sealed keyword indicates that the class cannot be inherited. (Seal)

Static class nature abstract + sealedstatic static class cannot be instantiated: Abstract static class cannot be inherited: sealed (Why cannot string be inherited)

Value Type reference type

Value types are implicitly derived from system. valuetype

1. numeric type, bool, structure, enumeration

The reference type is derived from system. object.

1. String, array, class, and interface

The value assignment of the reference type variable only copies the reference to the object. The value type variable value copies a copy.

Common class library string

1. the string is non-mutable.

2. String constant pool or detention pool

Common string Methods

Length // obtain the number of characters in the string.

Isnullorempty () static method, which is null or "" (static method)

Tochararray () converts string to Char []

Tolower () is in lower case and must receive the return value. (Because: the string is unchangeable );

Toupper () is capitalized.

Equals () is used to compare whether two strings are the same. Case-insensitive comparison,

Stringcomparation. indexof () If no corresponding data is found,-1 is returned.

Lastindexof () If no corresponding data is found,-1 is returned.

Substring () // two reloads to intercept the string.

Split () // split the string.

Join () Static Method

Format () Static Method

Replace ()

Common class library stringbuilder

Stringbuilder efficient string operations when a large number of string operations, such as many String concatenation operations. The string object is unchangeable. Every time you use a method in the system. string class, you must create a new String object in the memory, which requires a new space for the new object. If you need to modify the string repeatedly, the system overhead associated with creating a new String object may be very high. If you want to modify the string without creating a new object, you can use the system. Text. stringbuilder class. For example, when many strings are connected together in a loop, using the stringbuilder class can improve performance. Stringbuilder! = String

Convert stringbuilder to string. Use tostring ();

Stringbuilder is only a tool for concatenating strings. In most cases, you also need to convert stringbuilder to string.

Stringbuilder sb = new stringbuilder ();

SB. append (); // append a string

SB. tostring (); // converts stringbuilder to a string.

About binning: binning and unboxing must be: Value Type → reference type or reference type → Value Type

Comparison (equals, =)

1. Determine whether the object is the same: Determine whether the address in the stack is the same.

2. ==: (view string) internally calls

3. equals: the object determines whether the object address is the same, and the string determines whether the content is the same.

4. String overrides the equals method in the object.

5. When two variables point to the same memory, we will say that these two variables are the same object.

6. In fact, it is to determine whether the two variables point to the same memory address in the heap.

7. the equal of the string compares the content of the string, not the address of the object.

8. In the string, = is also the content of the comparison string.

9. In the string class, the inherited equals () method in the object parent class is overwritten (and a method is added), because after the = (operator overload) inside the operator, internally, equals is also called for implementation, so the results are the same.

10. Use referenceequals to compare whether an object is the same in any case.

11. Object. referenceequals (S1, S2): determines whether two objects are the same object.

BinarySerialization steps:

1. Create a binary serializer:

Binaryformatter BF = new binaryformatter ();

Create a file stream

Filestream FS = new filestream ();

2. Start serialization

BF. serialize (FS, P1 );

Note: 1. the object to be serialized should be marked as [serializable] ([serializableattribute]);

2. All fields in the serialized type must also be marked as [serializale];

3. All parent classes of the serialized type must be marked as [serializale].

Deserialization steps

1. Create a serializer and a file stream (same as above)

2. Execute deserialization object OBJ = BF. deserialize (FS );

Note: During deserialization, the Assembly where the serialization type is located needs to be created, because a new object needs to be created during deserialization. This object is of the original object type, assign values based on deserialization information after creation.

Delegation and events (this is not easy to understand and needs to be enhanced !)

To be honest, this is a bit tricky.

1. Define Delegation

Public Delegate void mydelegate (string S );

First, prepare a method, which is the same as the label requirements of the delegate.

Public void getname (string Str)

{

Person. Name = STR;

}

Delegate object

Mydelegate _ md;

In my understanding, delegate is a variable, but the method is stored in it.

Delegation is a data type. Through decompilation, we can see that the delegate is compiled into a class, so we can also instantiate the delegate object.

Generic Delegation

Public Delegate int comparsion <t> (t x, t y );

Built-in generic delegation:

Action <t> (no return value)

Func <t, tresult> (with returned values)

Regular Expression

For example, I want to use regular expressions to match the job information on the webpage, And to deduct images from the webpage.

WebClient WC = new WebClient (); string name = WC. downloadstring (@ "http: // localhost: 8080/Shanghai, it-management, computer software recruitment, job title: -51ili.htm"); matchcollection MA = RegEx. matches (name, @ "<A \ shref =" "http://search.51job.com/job/?d=8},c.html" "\ s. +> (. +) </a> "); For (INT I = 0; I <Ma. count; I ++) {If (MA [I]. success) {console. writeline (MA [I]. groups [1]. value) ;}} console. writeline (MA. count); console. readkey ();
View code

Today I took a day off. I was supposed to have slept till noon, but due to the painful lessons, I was unable to myself. Today I went to the classroom to study independently. Indeed, it is indeed better to study in the classroom than in the dormitory! Because of my own shortcomings, I will use this time for further tutoring in the future. I am very satisfied with every small step of progress. It takes a long time. I believe that I will gradually develop my own programming logic.

Remember so much today. I still have to practice code. cainiao can only work hard!

--- Restore content end ---

♠Code specifications

Camel naming: lowercase for the first word and userpassword for the first letter (common variables, local variables, fields)

Pascal's naming method: each word is capitalized with getname () (method name, attribute, class name)

.Csfile can be opened through the csc.exe program. When the program is running, it uses the JIT compilation (just in time) to instantly compile the Assembly into a machine code that can be understood by the CPU. Then, the CPU can execute

Object-oriented

Object-Oriented Programming (OOP → object-oriented programming)

OOA: object-oriented analysis object-oriented analysis

OOD: object-oriented design object-oriented design,

Ood OOAD: object-oriented analysis and design object orient Analysis Design

Object-oriented features: encapsulation, inheritance, and polymorphism. My understanding is that this is all for enhanced code reuse and program scalability.

Class: A class is a model. Determining the features (attributes) and behavior (methods) objects that an object will possess is a specific entity that you can see and feel-everything is an object.

Classes are abstract, while objects are instances of classes.

In a class, data is used to indicate the state of a thing, and functions are used to implement the behavior of a thing.

Attributes encapsulate fields and inherit (the relationship between classes .)

All classes are directly or indirectly inherited from objects.

The role of polymorphism: Different subclass objects are treated as parent classes, which can shield the differences between different subclass objects, write common code, and make common programming to adapt to the changing needs.

Notes for Virtual Methods:

1. If a method in the parent class needs to be overwritten by the subclass, you can mark this method as virtual

2. Virtual methods must be implemented in the parent class, even if they are empty implementations.

3. The virtual method subclass can be overwritten or not overwritten.

Notes for abstract methods:

1. You need to mark it with abstract keywords.

2. abstract methods cannot be implemented in any way.

3. Abstract members must be included in abstract classes.

4. Since abstract members are not implemented, the Child class must overwrite the abstract members.

5. abstract classes cannot be instantiated. The role of abstract classes is to inherit them.

6. abstract classes can include abstract members and members with specific code.

7. There are also abstract methods that cannot be modified using static

Note:

1. interfaces can only contain methods (attributes, events, and indexers are all methods)

2. Members in the interface cannot have any implementations.

3. The interface cannot be instantiated.

4. The interface members cannot have any access modifiers. (Public by default)

5. The subclass that implements the interface must implement all the members of the interface.

6. When subclasses implement interface methods, they can be directly implemented without any keywords.

7. The interface has the significance of polymorphism.

Methods that implement polymorphism include abstraction, virtual methods, and interfaces.

Give priority to the interface and then abstract the final virtual Method

When to use abstract classes and virtual methods?

Check whether this class needs to be instantiated in the future. If it needs to be instantiated, it cannot be abstract;

 

Five access Modifiers

PRIVATE: the default access modifier of the current class.

The current class and subclass of protected can be accessed (used in inheritance .)

Internal can be accessed inside the current Assembly

Protected internal in the current Assembly or subclass (different assembly can also be accessed ).

Public anywhere

Static class

Static classes cannot be inherited by other classes, and static members cannot be inherited (the same class is accessed)

Static classes can only inherit from object classes. (Static classes cannot inherit from other classes .)

Static classes cannot implement any interface (because all the members in the interface are instance members .)

Sealed :() the sealed class cannot be inherited.

The sealed keyword indicates that the class cannot be inherited. (Seal)

Static class nature abstract + sealedstatic static class cannot be instantiated: Abstract static class cannot be inherited: sealed (Why cannot string be inherited)

Value Type reference type

Value types are implicitly derived from system. valuetype

1. numeric type, bool, structure, enumeration

The reference type is derived from system. object.

1. String, array, class, and interface

The value assignment of the reference type variable only copies the reference to the object. The value type variable value copies a copy.

Common class library string

1. the string is non-mutable.

2. String constant pool or detention pool

Common string Methods

Length // obtain the number of characters in the string.

Isnullorempty () static method, which is null or "" (static method)

Tochararray () converts string to Char []

Tolower () is in lower case and must receive the return value. (Because: the string is unchangeable );

Toupper () is capitalized.

Equals () is used to compare whether two strings are the same. Case-insensitive comparison,

Stringcomparation. indexof () If no corresponding data is found,-1 is returned.

Lastindexof () If no corresponding data is found,-1 is returned.

Substring () // two reloads to intercept the string.

Split () // split the string.

Join () Static Method

Format () Static Method

Replace ()

Common class library stringbuilder

Stringbuilder efficient string operations when a large number of string operations, such as many String concatenation operations. The string object is unchangeable. Every time you use a method in the system. string class, you must create a new String object in the memory, which requires a new space for the new object. If you need to modify the string repeatedly, the system overhead associated with creating a new String object may be very high. If you want to modify the string without creating a new object, you can use the system. Text. stringbuilder class. For example, when many strings are connected together in a loop, using the stringbuilder class can improve performance. Stringbuilder! = String

Convert stringbuilder to string. Use tostring ();

Stringbuilder is only a tool for concatenating strings. In most cases, you also need to convert stringbuilder to string.

Stringbuilder sb = new stringbuilder ();

SB. append (); // append a string

SB. tostring (); // converts stringbuilder to a string.

About binning: binning and unboxing must be: Value Type → reference type or reference type → Value Type

Comparison (equals, =)

1. Determine whether the object is the same: Determine whether the address in the stack is the same.

2. ==: (view string) internally calls

3. equals: the object determines whether the object address is the same, and the string determines whether the content is the same.

4. String overrides the equals method in the object.

5. When two variables point to the same memory, we will say that these two variables are the same object.

6. In fact, it is to determine whether the two variables point to the same memory address in the heap.

7. the equal of the string compares the content of the string, not the address of the object.

8. In the string, = is also the content of the comparison string.

9. In the string class, the inherited equals () method in the object parent class is overwritten (and a method is added), because after the = (operator overload) inside the operator, internally, equals is also called for implementation, so the results are the same.

10. Use referenceequals to compare whether an object is the same in any case.

11. Object. referenceequals (S1, S2): determines whether two objects are the same object.

BinarySerialization steps:

1. Create a binary serializer:

Binaryformatter BF = new binaryformatter ();

Create a file stream

Filestream FS = new filestream ();

2. Start serialization

BF. serialize (FS, P1 );

Note: 1. the object to be serialized should be marked as [serializable] ([serializableattribute]);

2. All fields in the serialized type must also be marked as [serializale];

3. All parent classes of the serialized type must be marked as [serializale].

Deserialization steps

1. Create a serializer and a file stream (same as above)

2. Execute deserialization object OBJ = BF. deserialize (FS );

Note: During deserialization, the Assembly where the serialization type is located needs to be created, because a new object needs to be created during deserialization. This object is of the original object type, assign values based on deserialization information after creation.

Delegation and events (this is not easy to understand and needs to be enhanced !)

To be honest, this is a bit tricky.

1. Define Delegation

Public Delegate void mydelegate (string S );

First, prepare a method, which is the same as the label requirements of the delegate.

Public void getname (string Str)

{

Person. Name = STR;

}

Delegate object

Mydelegate _ md;

In my understanding, delegate is a variable, but the method is stored in it.

Delegation is a data type. Through decompilation, we can see that the delegate is compiled into a class, so we can also instantiate the delegate object.

Generic Delegation

Public Delegate int comparsion <t> (t x, t y );

Built-in generic delegation:

Action <t> (no return value)

Func <t, tresult> (with returned values)

Regular Expression

For example, I want to use regular expressions to match the job information on the webpage, And to deduct images from the webpage.

WebClient WC = new WebClient (); string name = WC. downloadstring (@ "http: // localhost: 8080/Shanghai, it-management, computer software recruitment, job title: -51ili.htm"); matchcollection MA = RegEx. matches (name, @ "<A \ shref =" "http://search.51job.com/job/?d=8},c.html" "\ s. +> (. +) </a> "); For (INT I = 0; I <Ma. count; I ++) {If (MA [I]. success) {console. writeline (MA [I]. groups [1]. value) ;}} console. writeline (MA. count); console. readkey ();
View code

Today I took a day off. I was supposed to have slept till noon, but due to the painful lessons, I was unable to myself. Today I went to the classroom to study independently. Indeed, it is indeed better to study in the classroom than in the dormitory! Because of my own shortcomings, I will use this time for further tutoring in the future. I am very satisfied with every small step of progress. It takes a long time. I believe that I will gradually develop my own programming logic.

Refer image, but I still have a headache for regular expressions.

WebClient WC = new WebClient (); string name = WC. downloadstring (@ "http: // localhost: 8080/ .htm"); matchcollection MC = RegEx. matches (name, @ "hotgirls/(%0-9a-za-z_%+.jpg)"); For (INT I = 0; I <MC. count; I ++) {If (MC [I]. success) {WC. downloadfile ("http: // localhost: 8080/" + Mc [I], @ "F: \ \" + Mc [I]. groups [1]. value) ;}} console. writeline ("download completed"); console. readkey ();
View code

Remember so much today. I still have to practice code. cainiao can only work hard!

Basic notes 1

Large-Scale Price Reduction
  • 59% Max. and 23% Avg.
  • Price Reduction for Core Products
  • Price Reduction in Multiple Regions
undefined. /
Connect with us on Discord
  • Secure, anonymous group chat without disturbance
  • Stay updated on campaigns, new products, and more
  • Support for all your questions
undefined. /
Free Tier
  • Start free from ECS to Big Data
  • Get Started in 3 Simple Steps
  • Try ECS t5 1C1G
undefined. /

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.