用户
 
密码
虚 拟 主 机
主 机 托 管
主 机 租 用
应 用 服 务
虚拟独立服务器



ASP.NET 功能列表
ASP.NET 主机FAQ
ASP.NET 快速入门
   什么是ASP.NET/优点何在?
可支持语言
ASP.NET Web窗体
  Web窗体介绍
ASP.NET Web服务
  Web服务介绍
ASP.NET 应用程序
  应用程序概述
缓存服务
  缓存概述
配置
   配置概述
配置文件格式
安全性
  安全性概述
本地化
     国际化概述 Overview
设置区域性和编码
本地化ASP.NET应用程序
使用资源文件
跟踪
    跟踪概述
跟踪记录到页输出
应用程序级跟踪记录
性能
    性能概述
性能优化提示
测量性能
ASP到ASP.NET的移植
     移植概述
语法和含义
语言兼容性
COM互操作性
示例应用程序
   个性化入口
电子商务店面
您的位置:首页>虚拟主机>ASP.NET

可支持语言


Microsoft .NET Platform 目前提供对以下三种语言的内置支持:C#、Visual Basic 和 JScript。

本教程中的练习和代码示例展示如何使用 C#、Visual Basic 和 JScript 生成 .NET 应用程序。有关其他语言语法的信息,请参考 .NET 框架 SDK 的完整文档。

提供下表以帮助您理解本教程中的代码示例以及三种语言之间的差异:

变量声明
Dim x As Integer
Dim s As String
Dim s1, s2 As String
Dim o 'Implicitly Object
Dim obj As New Object()
Public name As String
C# VB JScript

语句
Response.Write("foo")
C# VB JScript

注释
' This is a comment

' This
' is
' a
' multiline
' comment

C# VB JScript


访问索引属性
Dim s, value As String
s = Request.QueryString("Name")
value = Request.Cookies("Key").Value

'Note that default non-indexed properties
'must be explicitly named in VB

C# VB JScript


声明索引属性
' Default Indexed Property
Public Default ReadOnly Property DefaultProperty(Name As String) As String
Get
Return CStr(lookuptable(name))
End Get
End Property
C# VB JScript


声明简单属性
Public Property Name As String

Get
...
Return ...
End Get

Set
... = Value
End Set

End Property

C# VB JScript

声明和使用枚举
' Declare the Enumeration
Public Enum MessageSize

Small = 0
Medium = 1
Large = 2
End Enum

' Create a Field or Property
Public MsgSize As MessageSize

' Assign to the property using the Enumeration values
MsgSize = small

C# VB JScript

枚举集合
Dim S As String
For Each S In Coll
...
Next
C# VB JScript

声明和使用方法
' Declare a void return function
Sub VoidFunction()
...
End Sub

' Declare a function that returns a value
Function StringFunction() As String
...
Return CStr(val)
End Function

' Declare a function that takes and returns values
Function ParmFunction(a As String, b As String) As String
...
Return CStr(A & B)
End Function

' Use the Functions
VoidFunction()
Dim s1 As String = StringFunction()
Dim s2 As String = ParmFunction("Hello", "World!")

C# VB JScript

自定义属性
' Stand-alone attribute
<STAThread>

' Attribute with parameters
<DllImport("ADVAPI32.DLL")>

' Attribute with named parameters
<DllImport("KERNEL32.DLL", CharSet:=CharSet.Auto)>

C# VB JScript

数组
Dim a(2) As String
a(0) = "1"
a(1) = "2"
a(2) = "3"

Dim a(2,2) As String
a(0,0) = "1"
a(1,0) = "2"
a(2,0) = "3"

C# VB JScript

初始化
Dim s As String = "Hello World"
Dim i As Integer = 1
Dim a() As Double = { 3.00, 4.00, 5.00 }
C# VB JScript

If 语句
If Not (Request.QueryString = Nothing)
...
End If
C# VB JScript

Case 语句
Select Case FirstName
Case "John"
...
Case "Paul"
...
Case "Ringo"
...
Case Else
...
End Select
C# VB JScript

For 循环
Dim I As Integer
For I = 0 To 2
a(I) = "test"
Next
C# VB JScript

While 循环
Dim I As Integer
I = 0
Do While I < 3
Console.WriteLine(I.ToString())
I += 1
Loop
C# VB JScript

异常处理
Try
' Code that throws exceptions
Catch E As OverflowException
' Catch a specific exception
Catch E As Exception
' Catch the generic exceptions
Finally
' Execute some cleanup code
End Try
C# VB JScript

字符串连接
' Using Strings
Dim s1, s2 As String
s2 = "hello"
s2 &= " world"
s1 = s2 & " !!!"

' Using StringBuilder class for performance
Dim s3 As New StringBuilder()
s3.Append("hello")
s3.Append(" world")
s3.Append(" !!!")

C# VB JScript

事件处理程序委托
Sub MyButton_Click(Sender As Object,
E As EventArgs)
...
End Sub
C# VB JScript

声明事件
' Create a public event
Public Event MyEvent(Sender as Object, E as EventArgs)

' Create a method for firing the event
Protected Sub OnMyEvent(E As EventArgs)
RaiseEvent MyEvent(Me, E)
End Sub

C# VB JScript

向事件添加事件处理程序或从事件移除事件处理程序
AddHandler Control.Change, AddressOf Me.ChangeEventHandler
RemoveHandler Control.Change, AddressOf Me.ChangeEventHandler
C# VB JScript

强制类型转换
Dim obj As MyObject
Dim iObj As IMyObject
obj = Session("Some Value")
iObj = CType(obj, IMyObject)
C# VB JScript

转换
Dim i As Integer
Dim s As String
Dim d As Double

i = 3
s = i.ToString()
d = CDbl(s)

' See also CDbl(...), CStr(...), ...

C# VB JScript

带继承的类定义
Imports System

Namespace MySpace

Public Class Foo : Inherits Bar

Dim x As Integer

Public Sub New()
MyBase.New()
x = 4
End Sub

Public Sub Add(x As Integer)
Me.x = Me.x + x
End Sub

Overrides Public Function GetNum() As Integer
Return x
End Function

End Class

End Namespace

' vbc /out:libraryvb.dll /t:library
' library.vb

C# VB JScript

实现接口
Public Class MyClass : Implements IEnumerable
...

Function IEnumerable_GetEnumerator() As IEnumerator Implements IEnumerable.GetEnumerator
...
End Function
End Class

C# VB JScript

带 Main 方法的类定义
Imports System

Public Class ConsoleVB

Public Sub New()
MyBase.New()
Console.WriteLine("Object Created")
End Sub

Public Shared Sub Main()
Console.WriteLine("Hello World")
Dim cvb As New ConsoleVB
End Sub

End Class

' vbc /out:consolevb.exe /t:exe console.vb

C# VB JScript

标准模块
Imports System

Public Module ConsoleVB

Public Sub Main()
Console.WriteLine("Hello World")
End Sub

End Module

' vbc /out:consolevb.exe /t:exe console.vb

C# VB JScript

感谢2001 Microsoft Corporation教材提供

  关于我们 联系方式 招聘启事 网站地图 合作伙伴  

Copyright 2001-2008 商务中国(www.bizcn.com) 短信名片:商务中国
总部地址:厦门软件园盛世大厦1-4楼(软件技术服务大楼裙楼) 邮编:361005 电话:0592-2577888
传真:
0592-2577188(汇款底单专用)  0592-2577111(其它各类传真)
上海分公司:上海市南京西路1081弄30号 邮编:200041
《中华人民共和国电信与信息服务业务》经营许可证 闽B2-20070003 网站备案号:闽B2-20040189