Table of Contents C# OperatorsArithmetic OverflowTypes Reference TablesFUENTE: c 2001 Microsoft Corporation. All rights reserved.Integral Types TableFloating-Point Types TableDefault Values TableValue Types TableImplicit Numeric Conversions TableExplicit Numeric


Table of Contents



Keywords are predefined reserved identifiers that have special meanings to the compiler. They cannot be used as identifiers in your program unless they include @ as a prefix. For example, @if is a legal identifier but if is not because it is a keyword.

abstract event new struct as explicit null switch base extern object this bool false operator throw break finally out true byte fixed override try case float params typeof catch for private uint char foreach protected ulong checked goto public unchecked class if readonly unsafe const implicit ref ushort continue in return using decimal int sbyte virtual default interface sealed volatile delegate internal short void do is sizeof while double lock stackalloc else long static enum namespace string

FUENTE: c 2001 Microsoft Corporation. All rights reserved.

C# Operators

C# provides a large set of operators, which are symbols that specify which operations to perform in an expression. C# predefines the usual arithmetic and logical operators, as well as a variety of others as shown in the following table. In addition, many operators can be overloaded by the user, thus changing their meaning when applied to a user-defined type.

Operator category Operators Arithmetic + - * / % Logical (boolean and bitwise) & ! ~ && true false String concatenation + Increment, decrement ++ – Shift « » Relational == != ⇐ >= Assignment = += -= *= /= %= &= = = «= »= Member access . Indexing [] Cast () Conditional ?: Delegate concatenation and removal + - Object creation new Type information is sizeof typeof Overflow exception control checked unchecked Indirection and Address * → [] &

Arithmetic Overflow

The arithmetic operators (+, -, *, /) can produce results that are outside the range of possible values for the numeric type involved. You should refer to the C# Language Reference section on a particular operator for details, but in general:

  • Integer arithmetic overflow either throws an OverflowException or discards the most significant bits of the result (see below). Integer division by zero always throws a DivideByZeroException.
  • Floating-point arithmetic overflow or division by zero never throws an exception, because floating-point types are based on IEEE 754 and so have provisions for representing infinity and NaN (Not a Number).
  • Decimal arithmetic overflow always throws an OverflowException. Decimal division by zero always throws a DivideByZeroException.

When integer overflow occurs, what happens depends on the execution context, which can be checked or unchecked. In a checked context, an OverflowException is thrown. In an unchecked context, the most significant bits of the result are discarded and execution continues. Thus, C# gives you the choice of handling or ignoring overflow.

In addition to the arithmetic operators, integral-type to integral-type casts can cause overflow (for example, casting a long to an int) and are subject to checked or unchecked execution. Also note that bitwise operators and shift operators never cause overflow. Gabriel Moreno

FUENTE: c 2001 Microsoft Corporation. All rights reserved.

Types Reference Tables

The following reference tables summarize the C# types:

  • Built-in types
  • Integral types
  • Floating-point types
  • Default values
  • Value types
  • Implicit numeric conversions
  • Explicit numeric conversions

For information on formatting the output of numeric types, see Formatting Numeric Results Table.

FUENTE: c 2001 Microsoft Corporation. All rights reserved.

Built-in Types Table

The following table shows the keywords for built-in C# types, which are aliases of predefined types in the System namespace.

C# Type .NET Framework type bool System.Boolean byte System.Byte sbyte System.SByte char System.Char decimal System.Decimal double System.Double float System.Single int System.Int32 uint System.UInt32 long System.Int64 ulong System.UInt64 object System.Object short System.Int16 ushort System.UInt16 string System.String


All of the types in the table, except object and string, are referred to as simple types.

The C# type keywords and their aliases are interchangeable. For example, you can declare an integer variable by using either of the following declarations:

int x = 123;System.Int32 x = 123;

To display the actual type for any C# type use the system method GetType(). For example, the following statement displays the system alias that represents the type of myVariable:


You can also use the typeof operator

FUENTE: c 2001 Microsoft Corporation. All rights reserved.Integral Types Table

The following table shows the sizes and ranges of the integral types, which constitute a subset of simple types.

Type Range Size sbyte -128 to 127 Signed 8-bit integer byte 0 to 255 Unsigned 8-bit integer char U+0000 to U+ffff Unicode 16-bit character short -32,768 to 32,767 Signed 16-bit integer ushort 0 to 65,535 Unsigned 16-bit integer int -2,147,483,648 to 2,147,483,647 Signed 32-bit integer uint 0 to 4,294,967,295 Unsigned 32-bit integer long -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807 Signed 64-bit integer ulong 0 to 18,446,744,073,709,551,615 Unsigned 64-bit integer


If the value represented by an integer literal exceeds the range of ulong, a compilation error will occur.

FUENTE: c 2001 Microsoft Corporation. All rights reserved.

Floating-Point Types Table

The following table shows the precision and approximate ranges for the floating-point types.

Type Approximate range Precision float }1.5 ~ 10-45 to }3.4 ~ 1038 7 digits double }5.0 ~ 10-324 to }1.7 ~ 10308 15-16 digits

FUENTE: c 2001 Microsoft Corporation. All rights reserved.

Default Values Table

The following table shows the default values of value types returned by the default constructors. Default constructors are invoked by using the new operator, for example:

int myInt = new int();

The preceding statement has the same effect as the following statement:

int myInt = 0;

Remember that using uninitialized variables in C# is not allowed.

Value type Default value bool false byte char 'PALABRAS RESERVADAS VISUAL C++


El contenido original se encuentra en
Todos los derechos reservados para el autor del contenido original (en el enlace de la linea superior)
Si crees que alguno de los contenidos (texto, imagenes o multimedia) en esta página infringe tus derechos relativos a propiedad intelectual, marcas registradas o cualquier otro de tus derechos, por favor ponte en contacto con nosotros en el mail [email protected] y retiraremos este contenido inmediatamente

Top 20