Bring you into ASP. NET (2)

Source: Internet
Author: User

1.2.1 programming language of ASP. NET

Currently, the development languages supported by ASP. NET include VB. NET, C #. NET, JSCRIPT. NET, VC ++. NET, and other languages supported by. NET Framework. Here I will introduce the most common VB. NET and C #. NET.

1. Visual Basic. NET

Visual Basic. NET is the latest version of Visual Basic in. NET. Compared with VB 6, it adds many new or improved features, such as inheritance, interface, and Overloading ). These make it a powerful object-oriented language.

The biggest new feature of Visual Basic. NET is that it uses CLS (Common Language Specification, Common Language Specification) and CLR (Common Language Runtime, Common Language Runtime ). Because Visual Basic. NET complies with CLS, any CLS-compliant language can use the classes, objects, and components you have compiled using Visual Basic. NET. Similarly, Visual Basic. NET developers can freely use other classes, objects, and components written in CLS-compliant languages without worrying about the differences between languages.

Visual Basic. NET supports many new object-oriented features, such as inheritance, overloading, interfaces, and constructor. It also includes Exception Handling, representation, and some new data types.

1) Inheritance

Visual Basic. NET allows you to define the base class. Derived classes can inherit the attributes and methods of the base class. You can also use the method of the derived class to overwrite the method of the base class. All classes in VB. NET can be inherited by default. For example, you can inherit the existing classes in a form, because the form you designed is a class.

2) Exception Handling

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 automatically jumps to the Catch Block. Here, we can output an error message or give the user a friendly prompt, without causing program crash. In Finally, we can release some system resources, such as database connections.

3) Overloading)

By using overload, you can allow methods, attributes, or processes with different data types to use the same name. As shown in the following code:

Overloads Sub Display (ByVal theChar As 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 theDouble As Double)
'Add code that displays Double data.
End Sub

When different parameters are passed in to the Display method, different processes are run. This is useful when we use different data types.

4) Interface

Interfaces and Classes define methods and attributes, but unlike classes, interfaces do not provide methods. You can write the implementation in the class that inherits the interface.

From the above new features, we can see that VB. NET has completely become a brand new language. It also supports multiple threads. Due to the huge changes, many VB programmers began to wonder whether to learn VB. NET or C #. The debate over the advantages and disadvantages of optimized is still in progress. It is certain that if you can master. NET Framework, using that language is no longer important.

2. C #. NET

C # is a brand new programming language developed by Microsoft for the. Net platform. Although C # is like C, and C ++, C # is not like his predecessor. C # is a development language that is completely object-oriented. It features both rapid development of Visual Basic and powerful functions of C ++. Its style is similar to that of C, C ++, and Java. If you are a C, C ++, or Java programmer, you will find that you can use C # For Development quickly. Like VB. NET, C # can leverage the various benefits of running in public languages. For example: language interaction, garbage collection mechanism, enhanced security performance, and version compatibility.

1) Class

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

Next we will create a class for you:
Public class person
{
// Attributes and methods can be added here.
}

2) attributes

Using properties, we can use data members in the category. Now we add a name and age attribute to the person class above.
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

A method is a member of a class that executes operations or other behaviors. Now we add a ToString () method to the above 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:" + _ Age;
}
}

Like VB. NET, C # also provides inheritance, interfaces, and other object-oriented features.

Related Article

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.