.NET Framework Class Save (Part 1) (Www.jojoo.net) 2001-6-5 (Please double-click the automatic scroll to watch, click Stop, then hit ..)
First, basic concept
The .NET Framework is an environment for development, deployment, and running .NET applications, including ASP.NET, Public Language Runtime Environment (CLR), and .NET Framework class. There are many reports on ASP.NET and CLR. Relatively, the introduction of the .NET framework class is relatively rare.
The .NET Framework class is also a SYSTEM class, which provides a large number of core functions that we can use when constructing ASP.NET applications (and non-ASP.NET applications). The System class can be used in all .NET languages, so we can regard the System class as a .NET's Windows API. Unlike the Windows API, the System class provides an advanced interface similar to COM, which is quite easy to use.
Just as all other .NET classes, the System class also exists in the form of assembly (Assembly). The program set in .NET is similar to COM DLL or EXE file - it is a saving class code execution file. For example, the MATH class (including its properties and method definitions) is located in the Mscorlib.dll assembly. .NET has two types of assemblies - private assemblies, shared assemblies. Private assembly is a set of individual applications, usually in the application's bin directory; in contrast, shared assemblies can be used in multiple applications, and it should be loaded into the global assembly buffer by the creators of the assembly ( Equivalent to the system registry in .NET). The .NET System class belongs to the shared assembly.
If you have used Windows API, you must know that it is difficult to use the Windows API that it is difficult to identify and find which function to call it. There is no way to organize functions within Windows API DLL, which looks like all API calls are randomly piled up in a huge DLL. Fortunately, .NET class organizes hierarchies called Namespaces in accordance with logical relationships. For example, the Math class is a member of the System namespace. Namespaces can nest in the hierarchy. For example, the Adoconnection class is a member of the System.Data.ado class.
1.1 Quote The members in the namespace To use the class space in the namespace, we must find the specific class of the class in the hierarchy of the namespace, that is, through ".", The name is explicitly referenced. For example, to create an adoconnection object, we must use the following code (all examples of this article are written in Visual Basic, but no matter which .NET language, the basic concept is still the same):
DIM CNX as system.data.sql.sqlConnection CNX = new system.data.sql.sqlconnection (_ "server = (local); uid = sa; pwd =; database = pubs")
In addition to the above method, we can also simplify the reference to the class with the Import instruction. For example, the following code tells ASP.NET imports System.Data.SQL namespace into the current page:
<% @ Import namespace = "system.data.sql"%>
After importing the namespace, we can directly reference the name of the class, omit the namespace descriptions in front of all kinds of names. Creating an adoconnection object now is: DIM CNX As SqlConnection CNX = New SqlConnection ("Server = (local); UID = SA; PWD =; Database = PUBS")
It can be seen that a large number of inputs can be reduced using the Import instruction.
Many namespaces have been automatically imported by ASP.NET, we don't have to import these namespaces for simplifying name references. These namespaces are as follows:
System System.Collections System.Text System.Text.RegularExpressions System.Web System.Web.Caching System.Web.SessionState System.Web.Security System.Web.UI System.Web.UI.WebControls System.Web.UI.HtmlControls should Note that importing a higher namespace does not mean simultaneously importing the namespace below it below it. That is, the following IMPORT instruction only imports the class in the System.Data namespace, but does not import classes from system.data.ado, system.data.sql, and other namespace below:
<% @ Import namespace = "system.data"%>
1.2 Class members include a variety of members-attributes, methods (Field), events, and constructors for constructing classes. The property describes the feature of the class, such as the System.Array class has a length attribute. The method is the action that can be performed, for example, we can call the Array class sort method sort array. The domain is similar to attributes. For any specific application, we can treat domains like treating properties, such as the PI attribute of the MATH class returns the value of π. The event represents the actions we can respond to it, such as an event called InfMessage, which is triggered when the database provider sends a warning or prompt information. Finally, the constructor is a special method that is called when creating a new object. For example, when we create a new SqlConnection object, we call the constructor of this class and pass a database connection to it.
The members of the class can be one of the following two types: static member, instance member. Static members (also known as shared members) are members of all classes of instance sharing members, not dependent on the specific examples of the class. To use a static member, we only need to reference the name of the member by using the object. For example, the POW method of the System.Math class is a static member to calculate the multiplier of the value. The following code calculates 5 3 times:
Answer = Math.Pow (5, 3)
In contrast to static members, instance members depends on specific instance objects. It means that we must create an object instance before using the instance member of the class. For example, we can return a random number with instance members of the System.random class. The following code first creates a system.random type object, then set the value of the dblrandom variable to a random number:
DIM DBLRANDOM AS DOUBLE DIM RND As Random = New Random dblrandom = rnd.nextdouble
1.3 VB.NET Functions The History of members VB.NET languages for the System class is a growing long process. Although Microsoft has canceled many of the original VB function in VB.NET, many of the features in the VB.NET language are still repeated with the SYSTEM class. If you can choose, use the System class to almost always better than using VB.NET. Using the System class not only makes the code more easily ported to other languages, and makes the code more in line with future VB.NET versions, because in future VB.NET languages, Microsoft may continue to cancel some of the Early VB language features.
Second, the mathematical calculation system.math class contains a large number of domains and methods that can be used for mathematical calculations, and all of its members are static. The POW method of the System.math class can calculate the multiplier of the value. For example, we can calculate the circular area with Math.Pi domain and the POW method (DBLRADIUS is a circular radius), and Math.pi returns the circumference rate π:
DBLAREA = Math.pi * Math.Pow (DBLRADIUS, 2)
The square root of the value can be calculated using the SQRT method. For example, the following code calculates the square root of 64:
Answer = math.sqrt (64)
The absolute value of the value can be returned with the ABS method. For example, the following code returns the absolute value of -7.8, and the value of the Answer will be 7.8:
Answer = math.abs (-7.8)
The SIGN method can return a value of the value. If the value is negative, SIGN returns -1; if it is a positive number, SIGN returns 1; if it is 0, SIGN returns 0. The Round method is rounded into the closest integer. For example, the following code is rounding 3.4677789, the value of the Answer will be 3:
Answer = Math.Round (3.4677789)
If you want ROUND, a value between two integer values, such as 3.5, then Round always returns an even number of closer to this value. That is, Math.Round (3.5) return value is 4, and the return value of Math.Round (6.5) is 6. The FLOOR method is used to truncate a real number, and its return value is less than the maximum integer value of the specified value. For example, the following code is shorted 5.9, and the value of Answer will be 5:
Answer = Math.floor (5.9)
Note that the result of the FLOOR method is negatively different from what you think. For example, the return value of FLOOR (-5.9) should be -6.
In addition to these methods described above, the MATH class also contains many methods for performing triangulation and logarithm computing.
Third, generate random numbers System.random class to generate random numbers. However, different from the VB's RND function, system.random can return a decimal random number, and can also return an integer random number; System.random class automatically generates random number generators based on system dates and times.
Use System.random's nextDouble method to return a Double type random number between 0 and 1; use the next method to return random integers between the two integer values. NEXTDOUBLE and NEXT are all instance methods, so you have to create a system.random type object before using these methods. Below is a complete ASP.NET page, which shows how to generate 20 random numbers using these methods, where 10 random numbers are between 0 and 1, and 10 between 1 and 50:
<% @ Page language = "vb" explicit = "true"%>