步驟1:
在App_Code建立cs與vb資料夾
步驟2:
public class CSharpObject
{
public string Hello()
{
return "Hi...C#";
}
}
步驟3:
步驟4:
步驟2:
vb目錄裡面建立vbobj.vb內容如下
Imports Microsoft.VisualBasic
Imports Microsoft.VisualBasic
Public Class VBObject
Public Function Hello() As String
Return "Hi...VB"
End Function
End Class
Public Function Hello() As String
Return "Hi...VB"
End Function
End Class
cs目錄裡面建立csobj.cs內容如下
using System;
using System;
public class CSharpObject
{
public string Hello()
{
return "Hi...C#";
}
}
步驟3:
Web.config設定
步驟4:
前端頁面叫用
VB用法
'呼叫C#類別
Protected Sub btnCSharp_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnCSharp.Click
Dim myCSharpObject As New CSharpObject
txtMsg1.Text = myCSharpObject.Hello()
End Sub
'呼叫VB類別
Protected Sub btnVB_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnVB.Click
Dim myVBObject As New VBObject
txtMsg2.Text = myVBObject.Hello()
End Sub
CS用法
//呼叫C#類別
protected void btnCSharp_Click(object sender, EventArgs e)
{
CSharpObject myCSharpObject = new CSharpObject();
txtMsg1.Text = myCSharpObject.Hello();
}
//呼叫VB類別
protected void btnVB_Click(object sender, EventArgs e)
{
VBObject myVBObject = new VBObject();
txtMsg2.Text = myVBObject.Hello();
}
VB用法
'呼叫C#類別
Protected Sub btnCSharp_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnCSharp.Click
Dim myCSharpObject As New CSharpObject
txtMsg1.Text = myCSharpObject.Hello()
End Sub
'呼叫VB類別
Protected Sub btnVB_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnVB.Click
Dim myVBObject As New VBObject
txtMsg2.Text = myVBObject.Hello()
End Sub
CS用法
//呼叫C#類別
protected void btnCSharp_Click(object sender, EventArgs e)
{
CSharpObject myCSharpObject = new CSharpObject();
txtMsg1.Text = myCSharpObject.Hello();
}
//呼叫VB類別
protected void btnVB_Click(object sender, EventArgs e)
{
VBObject myVBObject = new VBObject();
txtMsg2.Text = myVBObject.Hello();
}
0 comments:
張貼留言