Skip to Content
Beginning ASP.NET 3.5: In C# and VB
book

Beginning ASP.NET 3.5: In C# and VB

by Imar Spaanjaars
March 2008
Intermediate to advanced content levelIntermediate to advanced
766 pages
21h 15m
English
Wrox
Content preview from Beginning ASP.NET 3.5: In C# and VB

5.2. Data Types and Variables

At first when you think about data, you may not realize that each piece of data has a data type. You may think that a computer would store the words Hello World in exactly the same way as today's date or the number 6. However, to be able to effectively work with data, many programming languages have different data types, where each data type is constrained to a specific type of information. Out of the box, the .NET Framework comes with a long list of data types that allows you to work with numbers (like Integer, Short, and Double), text strings (Char and String), dates (DateTime), true/false constructs (the Boolean), and more. A list with the most common types is described later in this section.

For each major type of data there is a special data type. To work with that type, you can store it in a variable that you need to declare first using the required data type. In VB.NET you use Dim myVariable As DataType while in C# you use DataType myVariable. The following example shows you how to declare two variables: an Integer (int in C#) to hold a number and a String (string in C#) to hold a piece of text:

VB.NET

' Declare a variable of type Integer to hold medium sized whole numbers.
Dim distanceInMiles As Integer

' Declare a variable to hold some text like a first name.
Dim firstName As String

C#

// Declare a variable of type int to hold medium sized whole numbers. int distanceInMiles; // Declare a variable to hold some text like a first name. string ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Beginning ASP.NET 4: in C# and VB

Beginning ASP.NET 4: in C# and VB

Imar Spaanjaars
Professional ASP.NET 3.5 SP1 Edition: In C# and VB

Professional ASP.NET 3.5 SP1 Edition: In C# and VB

Bill Evjen, Scott Hanselman, Devin Rader

Publisher Resources

ISBN: 9780470187593Purchase book