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 Integer

Examine the Integer type, which is 4 bytes, along with Int32, MinValue and MaxValue.
Integer. This is a core type in VB.NET programs. It is the default numeric type. Usually loops use the Integer type for their indexes.
Integer details. Because it is everywhere, it is worthwhile to explore this .NET type in more depth. This is a 4-byte numeric type. We can measure its memory usage in an array.ByteKeywords
An example. We test some important parts of the Integer type. The Integer is a Structure, but we think of it as a low-level native type in VB.NET.

Part 1: An Integer is declared with a Dim statement. It can store positive values, such as 1, and negative values, such as -1.

Part 2: Expressions in VB.NET do not change the value of variables—unless the variables are assigned to the expression result.

Part 3: In this language, an Integer is mapped to the System.Int32 type. It has a range of over 4 billion values.

Part 4: We allocate an Integer array. We determine that each Integer occupies 4 bytes (all data is stored within the array).

Structure
VB.NET program that tests Integer type Module Module1 Sub Main() ' Part 1: specify an Integer Dim. Dim number As Integer = 1 Console.WriteLine(number) number = -1 Console.WriteLine(number) ' Part 2: use expressions. Console.WriteLine(number = -1) Console.WriteLine(number + 100) ' Part 3: get type and maximum and minimum values. Console.WriteLine(number.GetType()) Console.WriteLine(Integer.MaxValue) Console.WriteLine(Integer.MinValue) ' Part 4: compute memory per Integer. Dim bytes1 = GC.GetTotalMemory(False) Dim array(100000) As Integer array(0) = 1 Dim bytes2 = GC.GetTotalMemory(False) Console.WriteLine((bytes2 - bytes1) / 100000) End Sub End Module Output 1 -1 True 99 System.Int32 2147483647 -2147483648 4.00032
Some important values. It is worthwhile to emphasize the minimum and maximum values for an integer. Often our programs will access Integer.MinValue and MaxValue for bounds.
Integer information: Mapped to: System.Int32 MinValue: -2147483648 MaxValue: 2147483647
Nullable Integer. An Integer is a value type, so it cannot be set to Nothing. But we can wrap an Integer in a Nullable Structure, with special syntax in VB.NET.Nothing

And: The nullable structure can be set to Nothing. We can use GetValueOrDefault to safely get the underlying numeric value (if any).

Nullable
VB.NET program that uses nullable Integer Module Module1 Sub Main() ' A nullable Integer can be a numeric value, or Nothing. Dim test As Integer? = 100 Console.WriteLine("GETVALUEORDEFAULT: {0}", test.GetValueOrDefault()) test = Nothing Console.WriteLine("GETVALUEORDEFAULT: {0}", test.GetValueOrDefault()) End Sub End Module Output GETVALUEORDEFAULT: 100 GETVALUEORDEFAULT: 0
Loops. As a fundamental type, the Integer is used in For loops as an index. In languages, the integer type (int) is usually optimized for performance.

Thus: In most programs, the int as a local variable is the fastest. It is worth keeping int for loop indexes.

For Each, For
A summary. Integer is a fundamental type in VB.NET programs. It is mapped to System.Int32, which makes it precisely equivalent, in the C# language, to int. It requires four bytes of memory.
Integer has well-known lower and upper values. It has low-level optimizations for performance. This core type is worth researching. It is used throughout software projects.
© 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