
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Test Type Operators in Dart Programming
There are certain cases where we want to check if a variable is of a certain data type or not. Dart provides two test type operators that we can make use of.
These two test type operators are −
is - return true if that variable of the type we are checking against
is! - return true if that variable is not of the type that we are checking against.
Syntax
The syntax of is operator looks something like this −
x is int
In the above example, x is the name of the variable and we are checking whether x is of data type int.
The syntax of is! operator looks something like this −
x is! int
In the above example, x is the name of the variables and we are checking whether x is of type int or not.
Let's see both these operators in action in Dart code.
Example
Consider the example shown below −
void main(){ var x = 25; print(x is int); print(x is bool); }
Output
true false
Example
An example of is! Is shown below:
void main(){ var x = 25; print(x is! int); print(x is! bool); }
Output
False true