Last active
December 19, 2015 14:49
-
-
Save Fhernd/5971573 to your computer and use it in GitHub Desktop.
Representación hexadecimal adyacente.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class TiposPrimitivos | |
{ | |
static void Main() | |
{ | |
// Prepresentación hexadecimal adyacente | |
int i = 7; // 0x7 | |
bool b = true; // 0x1 | |
char c = 'A'; // 0x41 | |
float f = 0.5f; // usa códificación de punto flotante de la IEEE | |
int x = 127; // Notación decimal | |
long y = 0x7F; // Notación hexadecimal | |
double d = 1.5; // Notación decimal | |
double millon = 1E06; // Notación exponencial | |
Console.WriteLine( 1.0.GetType()); // Double (double) | |
Console.WriteLine( 1E06.GetType()); // Double (double) | |
Console.WriteLine( 1.GetType()); // Int32 (int) | |
Console.WriteLine( 0xF0000000.GetType()); // UInt32 (uint) | |
long i = 5; // Conversión implícita sin pérdidda desde literal int a long | |
double x = 7.0; | |
float f = 4.5F; // Sin en el prefijo F la compilación falla. | |
decimal d = -1.23; // Sin en el prefijo M la compilación falla. | |
int x = 12345; // int entero de 32 bits. | |
long y = x; // Conversión implícita a entero de 64 bits | |
short z = (short) x; // Conversión explícita a entero de 16 bits. | |
float f1 = 3.14159F; | |
double d1 = f; | |
double d2 = 3.14159; | |
float f2 = (float) d2; | |
int i1 = 1; | |
float f1 = i1; | |
float f2 = 3.14159F; | |
int i2 = (int) f2; | |
int i1 = 100000001; | |
float f = i1; // La magnitud se conserva, pero hay pérdida de precisión | |
int i2 = (int) f; // Valor en i2 100000000 | |
short x = 1, y = 1; | |
short z = x + y; // Error de compilación | |
short z = (short) ( x + y ); // OK | |
int a = 2 / 3; // 0 | |
int b = 0; | |
int c = 5 / b; // lanza la excepción DivideByZeroException | |
int a = int.MinValue; | |
a--; | |
Console.WriteLine(a==int.MaxValue); // true | |
int x = int.MaxValue; | |
int y = unchecked( x + 1 ); | |
unchecked{ int z = x + 1; } | |
int x = int.MaxValue + 1; // Error tiempo de compilación | |
int y = unchecked( int.MaxValue + 1 ); // No hay ningún error | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment