vb.net入门 vbnet入门经典( 四 )


图 :【TestWebService】的运行界面
Form vb的代码清单如下:
Public Class Form Inherits System Windows Forms Form#Region Windows 窗体设计器生成的代码 Public Sub New ( ) MyBase New ( )该调用是 Windows 窗体设计器所必需的InitializeComponent ( )在 InitializeComponent ( ) 调用之后添加任何初始化End Sub 窗体重写处置以清理组件列表 Protected Overloads Overrides Sub Dispose ( ByVal disposing As Boolean ) If disposing ThenIf Not ( ponents Is Nothing ) Then ponents Dispose ( )End If End If MyBase Dispose ( disposing )End Sub Windows 窗体设计器所必需的Private ponents As System ComponentModel IContainer注意 以下过程是 Windows 窗体设计器所必需的可以使用 Windows 窗体设计器修改此过程不要使用代码编辑器修改它Friend WithEvents Button As System Windows Forms Button Friend WithEvents Button As System Windows Forms Button Friend WithEvents DataGrid As System Windows Forms DataGrid System Diagnostics DebuggerStepThrough ( )Private Sub InitializeComponent ( ) Me Button = New System Windows Forms Button ( ) Me Button = New System Windows Forms Button ( ) Me DataGrid = New System Windows Forms DataGrid ( ) CType ( Me DataGrid System ComponentModel ISupportInitialize ) BeginInit ( ) Me SuspendLayout ( ) Me Button FlatStyle = System Windows Forms FlatStyle Flat Me Button Location = New System Drawing Point ( ) Me Button Name = ButtonMe Button Size = New System Drawing Size ( ) Me Button TabIndex =Me Button Text = 绑定Me Button FlatStyle = System Windows Forms FlatStyle Flat Me Button Location = New System Drawing Point ( ) Me Button Name = ButtonMe Button Size = New System Drawing Size ( ) Me Button TabIndex =Me Button Text = 修改Me DataGrid DataMember =Me DataGrid Dock = System Windows Forms DockStyle Top Me DataGrid HeaderForeColor = System Drawing SystemColors ControlText Me DataGrid Name = DataGridMe DataGrid Size = New System Drawing Size ( ) Me DataGrid TabIndex =Me AutoScaleBaseSize = New System Drawing Size ( ) Me ClientSize = New System Drawing Size ( ) Me Controls AddRange ( New System Windows Forms Control ( ) {Me DataGrid Me Button Me Button } ) Me Name = FormMe Text = 测试Web ServiceCType ( Me DataGrid System ComponentModel ISupportInitialize ) EndInit ( ) Me ResumeLayout ( False )End Sub#End RegionPrivate Sub Button _Click ( ByVal sender As System Object ByVal e As System EventArgs ) Handles Button Click Dim MyService As New localhost Service ( ) DataGrid DataSource = MyService Binding ( ) DataGrid DataMember = Cust End SubPrivate Sub Button _Click ( ByVal sender As System Object ByVal e As System EventArgs ) Handles Button Click Dim MyService As New localhost Service ( ) Dim ds As DataSet = DataGrid DataSource Dim dsChanges As DataSet = ds GetChanges ( ) If Not ( dsChanges Is Nothing ) Thends Merge ( MyService Update ( dsChanges ) True ) End IfEnd SubEnd Class
六 总结
lishixinzhi/Article/program/net/201311/11839
VB.net 和C#.net 各有什么优缺点C#.net优点:
运算符重载 。不安全代码(指针和固定内存区)、 无符号整数、移位运算 。
VB的优点:
即时编译、静态事件绑定、条件异常捕获、COM兼容类、宽松的类型检查和变量声明、VisualBasicRuntime库、可选参数、带参数属性、模块等语言特征、动态数组 。
通过VB.NET开发好的程序绝对没有问题(包括DirectX游戏开发) 。虽然VB.NET的资料少,但是只要C#支持的VB.NET都支持(大体上这样 , 因为都要经过MSIL中间环节 。除了指针之类的VB.NET不支持C#支持,但是没有多大实际用处) 。
vb.net的资料以英文资料居多(只有英文资料才有看头,中国的没有什么好资料),得看看英文水平过不过关 。还有VB.NET的ide也比C#的IDE好得多,代码看得也舒服 。(C#的大括号{}太烦人) 。
至于VB6对C的帮助,只是理解上会容易一些,其它用处不大 。有VB6的基础学VBNET会方便一些,但是并不是会VB6就会VB.NET,它们差别也不小 。

推荐阅读