Microsoft 9GD00001 Computer Accessories User Manual


 
Chapter 2: Learning Just Enough C# or VB.NET: Basic Syntax 53
learn how to create custom types later. First, you need to learn about primitive types. The
primitive types are part of the programming languages and built into .NET. A primitive
type is the most basic type of data that you can work with in .NET, which can’
t be broken
into smaller pieces. In contrast, a custom type can be made up of one or more primitive
types, such as a Customer type that would have a name, an address, and possibly more bits
of data that are primitive types. Table 2-2 lists the primitive types and descriptions.
Looking at Table 2-2, remember that C# is case-sensitive and all of the primitive types
are lowercase. You can also see a third column for .NET types. Occasionally, you’ll see
code that uses the .NET type, which aliases the C# and VB language-specific types. The
following example shows how to declare a 32-bit signed integer in both C# and VB, along
with the .NET type:
C#:
int age1;
Int32 age2;
VB:
Dim age1 as Integer
Dim age2 as Int32
Table 2-2 Primitive Types
VB C# .NET Description
Byte byte Byte 8-bit unsigned integer
SByte sbyte SByte 8-bit signed integer
Short short Int16 16-bit signed integer
UInt16 ushort UInt16 16-bit unsigned integer
Integer int Int32 32-bit signed integer
UInt32 uint UInt32 32-bit unsigned integer
Long long Int64 64-bit signed integer
UInt64 ulong UInt64 64-bit unsigned integer
Single float Single 32-bit floating point
Double double Double 64-bit floating point
Boolean bool Boolean true or false
Char Char Char 16-bit Unicode character
Decimal decimal Decimal 96-bit decimal (used for money)
String string String String of Unicode characters