Delegate จะเก็บตําแหน่ง Address ของ Method ที่ต้องการจะเรียกใช้ ทําให้เราสามารถเรียกใช้ Method ใดๆ ผ่าน Delegate ได้ คุณอาจจะสงสัยว่า ทําไมไม่เรียกใช้ Function ตรงๆไปเลย ข้อดีของการเรียกผ่าน Delegate คือสามารถเรียก Mathod ของ Class อื่นได้
ตัวอย่างการใช้งาน ในบทความนี้ จะสร้างคลาส Class1 และคลาส Form1 โดยคลาส Class1 มี Delegate ชื่อว่า det สําหรับเรียกใช้ Method จากภายนอก ส่วนคลาส Form1 มี Method ชื่อ cal และ Form_Load

delegate class diagram การทํางานจะเริ่มจาก Form_Load โดยจะสร้าง Object ของคลาส Class1 หลังจากนั้นเรียก Method ชื่อ method1 โดยส่ง Adress ของ cal ไปให้กับ Delegate ในคลาส Class1 ทําให้คลาส Class1 สามารถเรียกใช้ Method cal จากคลาส Form_Load ได้ คลาส Class1
Public Class Class1
Public Delegate Function det(ByVal x As Integer, ByVal y As Integer)
Public Function method1(ByVal fnInput As det)
MsgBox(fnInput(9, 1)) 'เรียก Method จากภายนอก
End Function
End Class
คลาส Form1
Public Class Form1
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Dim obj As New Class1()
obj.method1(AddressOf cal) 'เรียก Method ของคลาส Class1 โดยที่คลาส Class1 จะไปเรียก Method cal ของคลาส Form1
End Sub
Public Function cal(ByVal x As Integer, ByVal y As Integer) As Integer
Return x + y
End Function
End Class
Output:

รูป Output โหลด Project ตัวอย่าง>>> delegate example vs2008 ข้อมูลเพิ่มเติมที่>>> artit-k.com/dev-callback-vb-net/
วิธีการ Set default printer device ใน CUPS บนระบบปฎิบัติการ linux สําหรับใครที่ยังไม่รู้จักว่า CUPS คืออะไร ไปอ่านเพิ่มเติมได้ที่ ติดตั้ง และ share printer to raspberry pi or linux computer
สวัสดีครับ เราจะมาดูวิธีการเพิ่มสินค้าใน WooCommerce Wordpress กันครับ เริ่มกันเลยครับ ให้เข้าไปที่หน้าควบคุมของ Wordpress ก่อนครับ
ในปี ค.ศ. 1972 Dennis Ritchie เป็นผู้คิดค้นภาษาซี เป็นคแรก แต่ยังไม่ได้รับความนิยม ต่อมาในปี ค.ศ. 1978 Brian Kernighan ได้ร่วมกับ Dennis Ritchie พัฒนามาตรฐานของภาษาซี ขึ้น เรียกว่า K&R 1(Kernighan &