USING VALUE TYPE
There are three general value type
built-in type User-defined type Enumerations Derived from System.Value
Built-in Value Types
Type(Visual Basic/C# alias) System.Sbyte (Sbyte/sbyte) System.Byte (Byte/byte) System.Int16 (Short/short) Bytes 1 1 2 Range -128-127 0 to 255 -32768 to 32767 User for Signed byte values Unsigned byte Interoperation and other specialized uses
System.Int32 (Integer/int)
System.UInt32 (UInteger/uint) System.Int64 (Integer/int)
4
4
-2147483648 to 2147483647
0 to 4294967295
Whole numbers and counters
Positive Whole numbers and counters
-9223372036854775808 Large Whole numbers to 9223372036854775807
Built-in Value Types
Type(Visual Basic/C# alias) System.Single (Long/long) System.Double (Double/double) System.Decimal (Decimal/decimal) Bytes 4 8 Range -3.402823E+38 to 3.402823E+38 -1.79769313486232+308 to 1.79769313486232+308 User for Floating point numbers Precise or large floating point numbers
10
Financial and scientific 792281625142643375935 calculations requiring 43950335 to great precision 792281625142643375935 43950335
BEST PRACTICES
El runtime optimizes the performance of 32-bits (int32, int16) for counters. For floating-point operations, Double is the most efficient type because those operations are optimized by hardware.
USING VALUE TYPE
Visual Basic y C# define aliases for them.
Using the alias is equivalent to using the full type name, so most programmers use the shorter aliases
OTHER VALUE TYPE
Type (Visual Basic/C# alias) Byte Range Use for
System.Char (Char/char) System.Boolean (Boolean/bool) System.IntPtr (none)
2 4 Plataformdependent
N/A N/A N/A
Single Unicode characters. True/False value Pointer to a memory address
System.DateTime (Date/date)
1/1/0001 Moments i n time 12:00:00 AM to !2/31/9999 11:59:59 PM
USING VALUE TYPE
When you assign between value-type variables, los datas is copied from one variable to the other and stored en two different locations on the stack. Even They funtions as objects, you can call methods on them. Traditionally variables names begin with a lowetcase letter in C# and are capitalized in Visual Basic. For Consistency between the languages
USING VALUE TYPE
Declare the variable as nullable if you want to be able to determinar whether a valur has not been assigned. For example: If you are storing data from a yes/no question on a form and the user did not answer the question, you should store a null type. Nullable<bool> b = null; Bool? B = null;
USING VALUE TYPE
Declaring a variale as nullable enables the HasValue and Value members. Use HasValue to detect whether or not a value been set: If(b.HasValue) Console.WrileLine(b is {0},b.Value); Else Console.WrileLine(b is not set);
User-Typed types are also called structures or simply structs. As with other value type, instances of userDefined types are stored on the stack. Struct behave nearly identical to class. You define you own sttructures by using the struct keyWork
How to Create User-Defined Type
Struct
Casi todas las estructuras comparten la misma sintaxis que las clases, aunque estn ms limitadas que stas: Dentro de una declaracin de estructura, los campos no se pueden inicializar a menos que se declaren como constantes o estticos. Una estructura no puede declarar un constructor predeterminado (es decir, un constructor sin parmetros) ni un destructor.
Struct
Las estructuras tienen las propiedades siguientes: Las estructuras son tipos de valor, mientras que las clases son tipos de referencia. A diferencia de las clases, se pueden crear instancias de las estructuras sin utilizar un operador new. Las estructuras pueden declarar constructores, pero deben utilizar parmetros. Una estructura no puede heredar de otra estructura o clase, ni puede ser la base de una clase. Todas las estructuras heredan directamente de System.ValueType, que hereda de System.Object. Una estructura puede implementar interfaces.
How to Create Enumerations
Enumerations are related symbols that have fixed values. Use enumerations to provide a list of choices for developers using your class. For Example: Enum Titles: int {Mr,Ms, Mrs, Dr};
How to Create Enumerations
If you Create an instance of the Title type, Visual Studio display a list of the available values when you assign a value to variable. The value of the variable is an integer it is easy to output the name of the symbol.
Simplify coding and improve code readibility by enabling yo to use meaningful symbols.
Titles t = Titles.Dr Console.WriteLine({0}., t); //Display DR