/// /// TUTORIAL RÁPIDO DE C# (C Sharp) /// (Parte 1) /// /// * Vía: http://www.csharp-station.com/Tutorial.aspx /// // ********************************** // * Tipos básicos de datos en C# (C Sharp) Type Size (bits) Range ======== =========== =========================================== sbyte 8 -128 to 127 byte 8 0 to 255 short 16 -32768 to 32767 ushort 16 0 to 65535 int 32 -2147483648 to 2147483647 uint 32 0 to 4294967295 long 64 -9223372036854775808 to 9223372036854775807 ulong 64 0 to 18446744073709551615 char 16 0 to 65535 Type Size (bits) Precision Range ======== =========== ==================== =========================== float 32 7 digits 1.5 x 10-45 to 3.4 x 1038 double 64 15-16 digits 5.0 x 10-324 to 1.7 x 10308 decimal 128 28-29 decimal places 1.0 x 10-28 to 7.9 x 1028 // ********************************** // * Arrays de variables/objetos en C# (C Sharp) string[] names = {"Cheryl", "Joe", "Matt", "Robert"}; // ********************************** // * Crear un programa básico en C# (C Sharp) // Namespace Declaration using System; // Program start class class WelcomeCSS { // Main begins program execution. static void Main() { // Write to console Console.WriteLine("Welcome to the Tutorial!"); } } //* o leyendo los parámetros que se pasan por consola using System; // Program start class class NamedWelcome { // Main begins program execution. static void Main(string[] args) { // Write to console Console.WriteLine("Hello, {0}!", args[0]); Console.WriteLine("Welcome to the Tutorial!"); } } // ********************************** // * Escribir/leer en la consola en C# (C Sharp) Console.WriteLine("Hello console!!"); // Write to console/get input Console.Write("What is your name?: "); Console.Write("Hello, {0}! ", Console.ReadLine()); Console.WriteLine("Welcome to the C# Station Tutorial!"); // * ó string name = Console.ReadLine(); // ********************************** // * Estructura de los métodos bool createAddress(string name) { Address addr = new Address(name); storeAddress(addr); return true; } // ********************************** // * Crear clases en C# (C Sharp) using System; public class Echo { string myString; public Echo(string aString) { myString = aString; } public void Tell() { Console.WriteLine(myString); } } public class Hello { public static void Main() { Echo h = new Echo("Hello my 1st C# object !"); h.Tell(); } } // ********************************** // * Estructuras de control en C# (C Sharp) // if, and else if, and else // Multiple Case Decision if (myInt < 0 || myInt == 0) { Console.WriteLine("Your number {0} is less than or equal to zero.", myInt); } else if (myInt > 0 && myInt <= 30) { Console.WriteLine("Your number {0} is in the range from 21 to 30.", myInt); } else { Console.WriteLine("Your number {0} is greater than 30.", myInt); } // switch with integer type switch (myInt) { case 1: Console.WriteLine("Your number is {0}.", myInt); break; case 2: Console.WriteLine("Your number is {0}.", myInt); break; case 3: Console.WriteLine("Your number is {0}.", myInt); break; default: Console.WriteLine("Your number {0} is not between 1 and 3.", myInt); break; } // while loop while (myInt < 10) { Console.Write("{0} ", myInt); myInt++; } // do-while loop do { // Print A Menu Console.WriteLine("Something\n"); } while (condition != false); // for loop for (int i=0; i < 20; i++) { if (i == 10) break; if (i % 2 == 0) continue; Console.Write("{0} ", i); } // foreach loop string[] names = {"Cheryl", "Joe", "Matt", "Robert"}; foreach (string person in names) { Console.WriteLine("{0} ", person); } // ********************************** // * Namespaces en C# (C Sharp) namespace ns1 { namespace ns2 { // Program start class class NamespaceCSS { // Main begins program execution. public static void Main() { // Write to console Console.WriteLine("This is a Namespace."); } } } }
miércoles, noviembre 03, 2010
Tutorial rápido de C# (C Sharp)
Parte 1: Conceptos básicos
Suscribirse a:
Enviar comentarios (Atom)
No hay comentarios:
Publicar un comentario