Web Studyaspnet.blogspot.com Babyneed.blogspot.com

ASP.Net Web Developer Guide

Power By: eXTReMe Tracker Powered by Blogger  
 
 
 
 

 

 
Important Links
 
   
     
 
Sitemap
 
   
   
 
Reference
 
   

Saturday, February 11, 2006

Description Data Type (Chapter 2)

Integral Numbers
Integral numbers are whole numbers that do not have decimal values. For instance: 1, 12353, and –10. If you are familiar with computer programming, you’ll probably recognize the Byte, Short, Integer, and Long data types.These are 8, 16, 32, and 64 bit integers respectively, and each requires different amounts of memory. In other words, they can hold different ranges of values. For example, the Integer data type can hold values from –2,147,483,648 to 2,147,483,647.
You can reference these data types by the names in the preceding paragraph, or by the .NET names: System.Int, System.Int16, System.Int32, and System.Int64. Either name will work—the choice is up to you.
Floating-Point Numbers
Floating-point numbers are numbers with fractions or decimal points, such as 3.141592654 or –0.45.The specific data types are: Single (System.Single, 4 byte), Double (System.Double, 8 byte), and Decimal (System.Decimal, 12 byte). Let’s take a look at a simple example.The following code illustrates the difference between integers and floating-point numbers:
1: dim intA, intB as Integer
2: dim fltA, fltB as Single
3:
4: intA = 4
5: fltA = 5.6
6: intB = intA * fltA
Line 6 should return the value 22.4, but since we’ve assigned it to intB, an Integer, the returned value is 22—ASP.NET has dropped the decimal point.The following line, however, will return the correct answer:
7: fldB = intA * fltA
Be sure to use the proper data type for your applications!
Dates
A DateTime data type can be in many formats:“5/6/01,”“Wednesday, July 4th, 2001,” or “8:30:34 PM,” for example.This provides you with great flexibility in representing your date values, and enables you to perform simple arithmetic (such as adding or subtracting days or hours) on your values. As you move through this book, you’ll encounter many of these operations.
There is another date data type that you won’t use as often, but is helpful to know: the TimeSpan data type, which represents a time interval such as “8 hours” or “13 days.” Note that it cannot be used to hold specific times, such as “8 PM.” Use the DateTime type for these values instead.
Strings
The String data type that most programmers are familiar with is actually a class in VB.NET, rather than a primitive.This enables you to create new instances, override, and inherit from a String, which gives the programmer a lot of power when designing applications.This is probably one of the most common classes you’ll be using in your ASP.NET applications. There is also the Char data type, which represents a single Unicode character.
Because it is Unicode, it can represent a lot more than just the alphanumeric characters, in case you ever need to use them.You’ll see methods that will enable you to convert from Chars to Strings.
Booleans
Booleans are simply true-or-false values, such as 1/0, yes/no, and so on. Although the Boolean data type in VB.NET strictly uses true/false to represent data, you can easily convert it to the other pairs of values.
Objects
Finally, the Object data type is a generic type that’s used for a variable if no other type is specified. For example, if you use the VB.NET statement, then you’ll be creating an Object data type:
Your ASP.NET pages automatically import the System namespace, so you needn’t import it explicitly. For example, the ASP.NET page shown in Figure 2.1 is equivalent to Figure 2.2—the latter is probably easier for the developer, and doesn’t hurt performance at all.
Figure 2.1 Importing the System Namespace Explicitly
1: <%@ Page Language="VB" %>
2: <%@ Import Namespace="System" %>
3: <script runat="server">
4: dim MyInt as System.Integer
5: </script>
Figure 2.2 Allowing ASP.NET to Implicitly Import the System Namespace
1: <%@ Page Language="VB" %>
2: <script runat="server">
3: dim MyInt as Integer
4: </script>
The System namespace also includes one more object that is very useful for ASP.NET developers: the Array. Even though this class belongs to the System namespace, we’ll discuss it in the next section, under System.Collections.
Table 2.2 lists all of the namespaces directly under the System namespace—it’s quite a long list, and each of these namespaces often have even more subnamespaces. We’ll cover a few of the more important ones (when dealing with ASP.NET) in the subsequent sections.

0 Comments:

Post a Comment

<< Home