TheDeveloperBlog.com

Home | Contact Us

C-Sharp | Java | Python | Swift | GO | WPF | Ruby | Scala | F# | JavaScript | SQL | PHP | Angular | HTML

<< Back to VBNET

VB.NET AddressOf Operator

Use the AddressOf operator to specify a Function as a delegate argument.
AddressOf enables delegate Functions. With it we reference a method and use it as the implementation for a delegate. We use the name of a function and specify it where a delegate is required.LambdaFunction
Example. First, this program introduces the IsThreeLetters Function, which receives a String and returns a Boolean. This Function is used as a delegate. The Main entry point creates a List and adds 3 values to it.List

Then: The List.Find Function is used to find the first 3-letter String in the List instance.

List Find, Exists

AddressOf: The AddressOf operator is used and it references the IsThreeLetters Function. We display the result.

Console
VB.NET program that uses AddressOf Module Module1 Function IsThreeLetters(ByVal value As String) As Boolean Return value.Length = 3 End Function Sub Main() Dim list As List(Of String) = New List(Of String) list.Add("mouse") list.Add("horse") list.Add("dog") Dim value As String = list.Find(AddressOf IsThreeLetters) Console.WriteLine(value) End Sub End Module Output dog
Discussion. In the C# language, you do not need AddressOf. Instead, you can use the method name directly as the delegate. The AddressOf operator may be less confusing. It introduces the context in which the method name should be referenced.

And: It tells you that the method name is just used to acquire a memory address.

Summary. The AddressOf operator provides an excellent way for you to reference an existing Function and turn it into a delegate. This means you do not need to use lambda expression syntax. You can use existing functions.
© TheDeveloperBlog.com
The Dev Codes

Related Links:


Related Links

Adjectives Ado Ai Android Angular Antonyms Apache Articles Asp Autocad Automata Aws Azure Basic Binary Bitcoin Blockchain C Cassandra Change Coa Computer Control Cpp Create Creating C-Sharp Cyber Daa Data Dbms Deletion Devops Difference Discrete Es6 Ethical Examples Features Firebase Flutter Fs Git Go Hbase History Hive Hiveql How Html Idioms Insertion Installing Ios Java Joomla Js Kafka Kali Laravel Logical Machine Matlab Matrix Mongodb Mysql One Opencv Oracle Ordering Os Pandas Php Pig Pl Postgresql Powershell Prepositions Program Python React Ruby Scala Selecting Selenium Sentence Seo Sharepoint Software Spellings Spotting Spring Sql Sqlite Sqoop Svn Swift Synonyms Talend Testng Types Uml Unity Vbnet Verbal Webdriver What Wpf