Good habits are very important for the growth of people, and good programming habits are also very important for the improvement of our programming capabilities. We should have a good style in programming, the logic of source code is concise and clear, and easy to read and understand is an important standard for good programs. Making our programs more approachable and more vivid is of great benefit to our programming. It can also help us get twice the result with half the effort. The unwritten standards observed during programming are beneficial to our communication with others and our re-learning. After all, sometimes the program we write is not just for ourselves, nor is it on the rise, No matter later. Good coding makes the source code readable and meaningful, consistent with other language conventions, and as intuitive as possible.
1. Handle other errors)
The most basic requirement for program robustness is the processing and capturing of program errors. in ASP. NET, the error processing mechanism is the same as that in other programming languages. You can use Try... Catch... Finally and so on, which is greatly improved compared with ASP. In addition, using these error handling methods can greatly improve the readability and debugging speed of the program. When combining these advantages, we should pay more attention to this.
2. string processing
In web design, string processing is almost the most common. Use ASP.. NET, the string processing speed is faster than ASP. NET, specifically added a string processing class StringBulider, using this class can complete some common string operations, and most importantly, using StringBuilder can greatly improve the string processing speed.
In ASP. NET, the most common is to use "&" to connect two strings:
- Dim myOutputString As String = "My name is"
- Dim myInputString As String = " Alex"
- myOutputStringmyOutputString = myOutputString & myInputString
- Response.Write(myoutputString)
Now let's take a look at the use of StringBuilder. When using StringBuilder, we can perform some basic operations on strings, such as Append, Replace, Insert, and Remove, now let's take a look at the specific example.
1) Use Append in StringBuilder
Append is the same as Append in other languages, that is, adding other characters at the end of the string.
- Dim sb as StringBuilder = New StringBuilder()
- sb.append( "<table border=\\\'1\\\' width=\\\'80%\\\'>" )
- For i = 0 To RowCount - 1
- sb.Append("<tr>")
- For k = 0 To ColCount - 1
- sb.Append("<td>")
- sb.Append( dt.Rows(i).Item(k, DataRowVersion.Current).toString())
- sb.Append( "</td>" )
- Next
- sb.Append("<tr>")
- Next
- sb.Append( "</table>")
- Dim strOutput as String = sb.ToString()
- lblCompany.Text = strOutput
In the above program, the Append method is used to output a table. Note that the StringBulider must first use ToString () the method can be converted to the String type for direct output. In the above example, all we see is a direct string of Append. In fact, this method has a very convenient function, that is, it can directly Append other types of variables, for example, you can Appemd a value of the Integer type directly. Of course, the output will be automatically converted into a string:
- Sub Page_Load (Source As Object, E As EventArgs)
- Dim sb As System. Text. StringBuilder
- Dim varother As Integer
- Varother=9999
- Sb=NewSystem. Text. StringBuilder ()
- Sb. append ("<Font Color=\\ 'Blue \\\'>You can Append other types:</Font>")
- Sb. append (varother)
- Response. write (sb. toString ())
- End Sub
2) use of other methods in strings
We can also use other methods to look at the common ones:
Insert method. you can Insert other characters at the specified position. Use this method: Insert position, Insert character );
The Remove method can be used to delete a specified number of characters at a specified position. Usage: Remove the actual position, number of characters );
The Replace method can replace a specified character. Usage: Replace is replaced by a string)
3. Close the Connection and DataReader of the database.
When programming with ASP, we know that after connecting to a database, we must close the connection and set it to NoThing. In Asp. NET, we still need to use it like this, however, in ASP. NET, due to the use of ADO. NET. Therefore, there are some subtle differences in some related processing. These differences are often the most important during our design. Now, let's take an example to see what issues need to be paid attention to in common ADO. NET operations.
- Introduction to ASP. NET Framework
- Introduction to ASP. NET Applications
- Processing Methods of ASP. NET framework
- Analysis on ASP. NET Security Architecture
- Overview ASP. net mvc and FubuMVC core framework