推荐找一本C#的基础的书看了,我这里有一本要的话发给你好了。像你上面说的那种叫做“重载”,它重载的是“构造函数”。例如public class SqlConnection { public SqlConnection() public SqlConnection(string conn) public SqlConnection(Object ob) }像这个类就有3个构造函数,我们可以用下面3种方法实例化。SqlConnection conn = new SqlConnection(); string str = "ConoString"; SqlConnection conn = new SqlConnection(str); Object ob = new Object() SqlConnection conn = new SqlConnection(ob);
VB.net中和这用法一样吗?我是在VB.net中这样用的,可是不对
这个是C#,VB是这样的:Public Class SqlConnection
Public Sub New() MyBase.New End Sub
Public Sub New(ByVal conn As String) MyBase.New End Sub
Public Sub New(ByVal ob As Object) MyBase.New End Sub End ClassDim conn As SqlConnection = New SqlConnection Dim str As String = "ConoString" Dim conn As SqlConnection = New SqlConnection(str) Dim ob As Object = New Object
{
public SqlConnection()
public SqlConnection(string conn)
public SqlConnection(Object ob)
}像这个类就有3个构造函数,我们可以用下面3种方法实例化。SqlConnection conn = new SqlConnection();
string str = "ConoString";
SqlConnection conn = new SqlConnection(str);
Object ob = new Object()
SqlConnection conn = new SqlConnection(ob);
Public Sub New()
MyBase.New
End Sub
Public Sub New(ByVal conn As String)
MyBase.New
End Sub
Public Sub New(ByVal ob As Object)
MyBase.New
End Sub
End ClassDim conn As SqlConnection = New SqlConnection
Dim str As String = "ConoString"
Dim conn As SqlConnection = New SqlConnection(str)
Dim ob As Object = New Object