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 IsNot and Is Operators

Test against Nothing using the IsNot and Is operators in if-Statements.
Is, IsNot. We use these operators to check reference types. With these, we can check reference types against special value such as Nothing.
Some notes. We compare references to Nothing. The "Is" and "IsNot" operators are most often used with the Nothing constant. We can (for example) detect a null string.Nothing
Example. We see how "IsNot Nothing" and "Is Nothing" are evaluated with a local variable. This pattern of code is useful. It helps if you are not sure the variable is set to something.
VB.NET program that uses Is, IsNot operators Module Module1 Sub Main() Dim value As String = "cat" ' Check if it is NOT Nothing. If value IsNot Nothing Then Console.WriteLine(1) End If ' Change to Nothing. value = Nothing ' Check if it IS Nothing. If value Is Nothing Then Console.WriteLine(2) End If ' This isn't reached. If value IsNot Nothing Then Console.WriteLine(3) End If End Sub End Module Output 1 2
Is, IsNot notes. These operators can only be used with reference types. The Nothing constant is a special instance of a reference type. We cannot use the Is-operator to perform casting.

Note: These are most commonly used with the Nothing constant. But any two references can be compared.

And: The result depends on the memory locations—not the object data the references point to.

A review. Reference types are common in VB.NET programs—we create them based on classes. Things like Strings and StringBuilders are reference types.Class
© 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