First knowledge ASP.NET (2)

xiaoxiao2021-03-06  126

1.2.1 programming language for ASP.NET

?? The development language supported by ASP.NET includes VB.NET, C # .NET, JScript.net, VC . Net, and other languages ​​supported by other .NET Framework. Here I introduce you the most common VB.NET and C # .NET.

?? 1. Visual Basic.Net

?? Visual Basic.net is the latest version of Visual Basic in .NET. It compares to VB 6, adds many new or improved features - for example: inheritance, interface, overloading. These make it a powerful object-oriented language.

Visual Basic.Net's largest new feature is whose CLS (Common Language Specification, public language specification) and CLR (Common Language Runtime). Because Visual Basic.net follows CLS, this allows any language that follows CLS to use the classes, objects, and components you have written with Visual Basic.net. Similarly, Visual Basic.NET developers can also freely use other classes, objects, and components written in language compliance with CLS, without having to worry about the differences between languages.

Visual Basic.NET supports many new object-oriented features, such as inheritance, overload, interfaces, structures, and the like. Also included with abnormal processing, representative, and some new data types.

?? 1) Inheritability

?? Visual Basic.net allows you to define the base class, derived classes to inherit the properties and methods of the base class. You can also use a method of derived class to cover the base class. All classes in VB.NET are inherited by default. If you can inherit the class in an existing form in a form, because the form you design is a class.

?? 2) abnormal processing

?? VB.NET supports structured exception handling, you can use the following code to capture exceptions:

?? Try

?? '"try" block.

?? Catch e as classloadexception

?? '"catch" block.

?? Finally

?? '"finally" block.

?? End Try

?? Put your code in the TRY block. When an exception occurs, the program will automatically jump to the Catch block, here, we can output the error message, or give the user a friendly tip without causing the program to crash. In the Finally section, we can use some system resources such as database linkages.

?? 3) Overloading (OVERLOAD)

?? Use the overload you allow methods, properties, or processes that allow different data types to use the same name. As shown in the following code:

??

?? Overloads Sub Display (Byval thecha is char)

?? 'add code That Displays Char Data.

?? End Sub

?? overloads sub display (byval theinteger as integer)

?? 'add code That Displays Integer Data.

?? End Sub

?? Overloads Sub Display (Byval Tiedouble as Double)

?? 'add code That Displays Double Data.

?? End Sub

• When you pass different parameters to the Display method, it runs different processes. This is very useful when we use different data types.

?? 4) interface

?? Interface and classes will define methods and properties, but different from the classes, the interface does not provide the implementation of the method. You can write the implementation in the class of inherited interfaces. ?? From these new features, we can see that VB.NET has completely become a new language. It also provides support for multi-threaded, and so on. Due to its large change, many VB programmers have also begun to be confused to learn VB.NET, or learn C #. The controversy is still in progress, it is certain that if you can master the .NET Framework, it has become no longer important to use the language.

??

?? 2. C # .NET

?? C # language is a brand new programming language developed by Microsoft. Although C # is like a C, and C language upgrade language, he is not like his predecessor, C # is a full-scale development language. It has the characteristics of rapid development of Visual Basic, and has a powerful function of C . Its style is similar to C, C and Java. If you are a C, C or Java programmers, you will find that you can develop quickly using C #. Like VB.NET, C # can use the benefits to us by using public language operations. For example: language interactive, garbage collection mechanism, enhanced security, and version compatible.

?? 1) class

?? A class can inherit from another class, in C #, the class cannot inherit multiple classes, but it can inherit multiple interfaces.

?? Here we create a class for everyone:

?? Public Class Person

?? {

?? // This can increase the attributes and methods here.

??}

?? 2) attribute

?? Use properties, we can access data members in the class. We now add a name and age attribute to the above Person class.

?? Public Class Person

?? {

?? private string _name;

?? private int _age;

?? public string name

?? {

?? get

?? {

?? return _name;

??}

?? set

?? {

?? _name = value;

??}

??}

?? public int Age

?? {

?? get

?? {

?? Return_Age;

??}

?? set

?? {

?? _AGE = Value;

??}

??}

??}

?? 3) method

?? The method is a member of the class to perform an operation or other acts. We now add a method for Tostring () to the class.

?? Public Class Person

?? {

?? private string _name;

?? private int _age;

?? public person ()

?? {

?? //

?? // Todo: add constructor logic here

?? //

??}

?? public string name

?? {

?? get

?? {

?? return _name;

??}

?? set

?? {

?? _name = value;

??}

??}

?? public int Age

?? {

?? get

?? {

?? Return_Age;

??}

?? set

?? {

?? _AGE = Value;

??}

??}

??

?? public string toString ()

?? {

?? Return name: " _ name ", age: " _ agn;

??}

??}

• Like VB.NET, C # also provides other object-oriented properties such as inheritance, interfaces. ???????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????

转载请注明原文地址:https://www.9cbs.com/read-125762.html

New Post(0)