asp.net 1.2.1 ASP. NET programming language
Now the development languages supported by ASP.net include vb.net, c#.net, JScript.NET, VC + +. NET and other languages supported by the. NET Framework. Here I introduce you to the most commonly used 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-for example, inheritance, interfaces, overloads (overloading). These make it a powerful object-oriented language.
The biggest new feature of Visual Basic.NET is its use of the CLS (Common Language specification, the Common Language specification) and the CLR (Common Language Runtime, the common language runtime). Because Visual Basic.NET is CLS-compliant, this enables any CLS-compliant language to use classes, objects, and components that you write with Visual Basic.NET. Similarly, Visual Basic.NET developers are free to use classes, objects, and components written in other CLS-compliant languages without worrying about differences between languages.
Visual Basic.NET supports many new object-oriented features, such as inheritance, overloading, interfaces, constructs, and so on. It also includes exception handling, delegates, and some new data types.
1) The Inheritance of
Visual Basic.NET allows you to define a base class that can inherit the properties and methods of the base class. You can also use a derived class method to override the base class method. Vb. NET can be inherited by default. You can inherit a class from an existing form in a form, because the form you are designing is itself a class.
2) Exception handling
Vb. NET supports structured exception handling, you can use the following code to catch exceptions:
Try
' Try ' block.
Catch e as ClassLoadException
' Catch ' block.
Finally
' Finally ' block.
End Try
Put your code in a try block, and when an exception occurs, the program automatically jumps to the catch block, where we can output the error message or give the user a friendly hint without causing the program to crash. In the finally section, we can use to release some system resources, such as database links.
3) overload (overloading)
Using overloads you can use the same name for methods, properties, or procedures that allow you to have different data types. 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 you pass a different parameter to the display method, it runs a different procedure. This is useful when we use different data types.
4) interface
Interfaces and classes define methods and properties, but unlike classes, interfaces do not provide a method implementation. You can write the implementation in the class that inherits the interface.
From the above new features, we can see that vb.net has become a completely new language. It also provides support for multithreading, and so on. Because of its great changes, many VB programmers are also beginning to confuse learning vb.net, or Learning C #. The argument is still ongoing, and it is certain that if you can master the. NET Framework, using that language has become less important.
2. C#.net
The C # language is a Microsoft company target. NET platform to develop a new programming language. Although C # is an upgrade language for C and C + + languages, unlike his predecessor, C # is a fully-object-oriented development language. It has the characteristics of the rapid development of Visual Basic, but also has the powerful functions of C + +. It is similar in style to C, C + +, and Java. If you are a C, C + + or Java programmer, you will find that you can use C # quickly to develop. Like VB.net, C # can take advantage of the various benefits that the common language runtime brings to us. Examples include language interactivity, garbage collection mechanisms, 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.
Here we set up a class for you:
public class Person
{
You can add properties and methods in this area.
}
2) Property
Using attributes, we can access data members in a class. We now 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 performs an operation or other behavior. We now 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 other object-oriented features such as inheritance, interfaces, and so on.
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