Anda di halaman 1dari 38

//Tabla del 4 usando el ciclo while using using using using System; System.Collections.Generic; System.Linq; System.

Text;

class tabla4 { static void Main(string[] args) { int i = 1; Console.WriteLine("Tabla de Multiplicar del 4"); while (i < 11) // Condicin al inicio { Console.WriteLine("4 * {0} = {1}",i,i*4); i++; } Console.ReadKey(); } }

//Tabla del 4 usando el ciclo do - while using using using using System; System.Collections.Generic; System.Linq; System.Text;

class tabla4ciclodw { static void Main(string[] args) { int i = 1; Console.WriteLine("Tabla de Multiplicar del 4"); do { Console.WriteLine("4 * {0} = {1}", i, i * 4); i++; } while (i < 11); // Condicin al Final Console.ReadKey(); } }

//Tabla del 4 usando el ciclo FOR using using using using System; System.Collections.Generic; System.Linq; System.Text;

class tabla4_ciclo_FOR { static void Main(string[] args) { int i = 1; Console.WriteLine("Tabla de Multiplicar del 4"); for (i = 1; i < 11; i++) //Condicin al inicio, pero con los parametros de cuantas veces lo har { Console.WriteLine("4 * {0} = {1}", i, i * 4); } Console.ReadKey(); } }

//Tabla de Multiplicar para cualquier nmero incluso decimales using using using using System; System.Collections.Generic; System.Linq; System.Text;

class tablas { static void Main(string[] args) { int i = 1; double n; Console.WriteLine("Ingrese el nmero de la tabla que desea mostrar: "); n = double.Parse(Console.ReadLine()); while (i < 11) { Console.WriteLine(n +" * {0} = {1}",i,i*n); i++; } Console.ReadKey(); } }

//Programa para nmero factorial using using using using System; System.Collections.Generic; System.Linq; System.Text;

class numerofactorial { static void Main(string[] args) { int i = 1, fact = 1, n = 0; Console.WriteLine("Numero a Evaluar: "); n = Int32.Parse(Console.ReadLine()); if (n < 0) Console.WriteLine("No Valido"); else if (n == 0 || n == 1) Console.WriteLine("Factorial de {0} es 1", n); { else for (i = 1; i<=n; i++) { fact = fact * i; } Console.WriteLine("Factorial de {0} es {1}",n,fact); Console.ReadKey(); } } }

//Figura de asteriscos using using using using System; System.Collections.Generic; System.Linq; System.Text;

class arbolito { static void Main(string[] args) { Console.WriteLine(" * "); Console.WriteLine(" *** "); Console.WriteLine(" ***** "); Console.WriteLine(" ******* "); Console.WriteLine(" ********* "); Console.WriteLine(" *********** "); Console.WriteLine("*************"); Console.ReadKey();

} }

//Imprime la figura de un triangulo usando ciclo FOR using using using using System; System.Collections.Generic; System.Linq; System.Text;

class triangulo { static void Main(string[] args) { int l, e, a; for (l = 1; l <= 7; l++) { for (e=7; e-l>0; e--) Console.Write(" "); for (a=1; a<=2*l-1; a++) Console.Write("*"); Console.WriteLine(); } Console.ReadKey(); } }

//Escribiendo valores erroneos using using using using System; System.Collections.Generic; System.Linq; System.Text;

class DemoTry { static void Main(string[] args) { int x = 0; Console.Write("x: "); x = Int32.Parse(Console.ReadLine()); Console.WriteLine("Escribio: " + x); Console.ReadKey(); } }

//Escribiendo valores erroneos using using using using System; System.Collections.Generic; System.Linq; System.Text;

class DemoTry1 { static void Main(string[] args) { int x = 0; Console.Write("x: "); try { x = Int32.Parse(Console.ReadLine()); Console.WriteLine("Escribio: " + x); } catch (FormatException e) //Tipo de excepcion de formato, //cuando se intenta asignar un valor //cuando el tipo de datos es diferente { Console.WriteLine("Mensaje: " + e.Message); Console.WriteLine("Tipo de datos invlido"); } Console.ReadKey(); } }

//Escribiendo valores erroneos y usando finally, funciona si el try es correcto e incorrecto using using using using System; System.Collections.Generic; System.Linq; System.Text;

class DemoTry1 { static void Main(string[] args) { int x = 0; Console.Write("x: "); try { x = Int32.Parse(Console.ReadLine()); Console.WriteLine("Escribio: " + x); } catch //Tipo de excepcion de formato, //cuando se intenta asignar un valor //cuando el tipo de datos es diferente { Console.WriteLine("Tipo de datos invlido"); } finally { Console.WriteLine("Uso de Finally"); } Console.ReadKey(); } }

//Verificando las excepciones using using using using System; System.Collections.Generic; System.Linq; System.Text;

class DemoTry2 { static void Main(string[] args) { try { Console.WriteLine("Antes de Throw"); throw new DivideByZeroException(); } catch { Console.WriteLine("Excepcion Atrapada"); } Console.WriteLine("Deses del try-catch"); Console.ReadKey(); } }

//Verificando las excepciones using using using using System; System.Collections.Generic; System.Linq; System.Text;

class DemoTry2 { static void Main(string[] args) { try { throw new MiExcepcion("Original"); } catch (DivideByZeroException e) { Console.WriteLine("Mensaje: " + e.Message); } Console.WriteLine("Deses del try-catch"); Console.ReadKey(); } }

// // // // // // // // // //

FormatException DivideByZeroException IndexOutOfRangeException OutOfMemoryException NullReferenceException ArrayTypeMismatchException ArithmeticException OverFlowException InvalidCastException StackOverFlowException

// creamos una excepcin para luego ser usada en el mtodo principal. using System; using System.Collections.Generic; using System.Linq; using System.Text; class MiException:Exception { public MiException() { Console.WriteLine("Excepcin definida por el usuario"); } }

class MiClienet { public static void Main() { try { throw new MiException(); } catch (Exception e) { Console.WriteLine("Excepcin atrapada Aqu: " + e.Message); } Console.WriteLine("ltima Sentencia"); Console.ReadKey(); } } //Tipo de Datos Retorno

using using using using

System; System.Collections.Generic; System.Linq; System.Text;

namespace ConsoleApplication1 { class Construccion { public int Pisos; public int Area; public int Ocupantes; public void MostrarAreaPorPersona() { Console.WriteLine(" " + Area / Ocupantes + " era por persona"); } } class ConstructcionDemo { static void Main() { Construccion casa = new Construccion(); Construccion oficina = new Construccion(); casa.Ocupantes = 4; casa.Area = 2500; casa.Pisos = 2; oficina.Ocupantes = 25; oficina.Area = 4200; oficina.Pisos = 3; Console.Write("La casa tiene \n" + casa.Pisos + " Pisos \n" + casa.Ocupantes + " ocupantes\n" + casa.Area + " rea Total \n"); casa.MostrarAreaPorPersona(); Console.WriteLine("\n\n"); Console.Write("La oficina tiene \n" + oficina.Pisos + " pisos\n" + oficina.Ocupantes + " ocupantes \n" + oficina.Area + " area Total \n"); oficina.MostrarAreaPorPersona(); Console.ReadKey(); }

} }

using using using using

System; System.Collections.Generic; System.Linq; System.Text;

namespace ConsoleApplication1 { class Construccion { public int public int public int public int { return } Pisos; Area; Ocupantes; MostrarAreaPorPersona() Area/Ocupantes;

} class ConstructcionDemo { static void Main() { Construccion casa = new Construccion(); Construccion oficina = new Construccion(); int areaPP; casa.Ocupantes = 4; casa.Area = 2500; casa.Pisos = 2; oficina.Ocupantes = 25; oficina.Area = 4200; oficina.Pisos = 3; Console.Write("La casa tiene \n" + casa.Pisos + " Pisos \n" + casa.Ocupantes + " ocupantes\n" + casa.Area + " rea Total \n"); areaPP = casa.MostrarAreaPorPersona(); Console.WriteLine(" " + areaPP + " era por persona"); Console.Write("La oficina tiene \n" + oficina.Pisos + " pisos\n" + oficina.Ocupantes + " ocupantes \n" + oficina.Area + " area Total \n"); areaPP = oficina.MostrarAreaPorPersona(); Console.WriteLine(" " + areaPP + " era por persona"); Console.ReadKey(); }

} }

using using using using

System; System.Collections.Generic; System.Linq; System.Text;

class Construccion { public int pisos; public int area; public int ocupantes; public int areaporpersona() { return area / ocupantes; } public int maxocupantes(int minarea) { return area / minarea; } } class ConstruccionDemo { static void Main(string[] args) { Construccion casa = new Construccion(); Construccion oficina = new Construccion(); casa.ocupantes = 4; casa.area = 2500; casa.pisos = 2; oficina.ocupantes = 25; oficina.area = 4200; oficina.pisos = 3; Console.WriteLine("Mximo de ocupantes para casa s cada uno tiene 300 metros cuadrados: "+ casa.maxocupantes(300)); Console.WriteLine("Mximo de ocupantes para casa s cada uno tiene 300 metros cuadrados: " + oficina.maxocupantes(300)); Console.ReadKey(); } } using System; using System.Collections.Generic;

using System.Linq; using System.Text;

enum colorsemaforo { ROJO, AMARILLO, VERDE }; class semaforo { public colorsemaforo color = colorsemaforo.ROJO; public bool intermitente = false; } class pruebasemaforo { static void Main(string[] args) { semaforo s1 = new semaforo(); Console.WriteLine("El semforo se encuentra en: " + s1.color); s1.color = colorsemaforo.AMARILLO; Console.WriteLine("El semforo se encuentra en: " + s1.color); Console.ReadKey(); } }

using using using using

System; System.Collections.Generic; System.Linq; System.Text;

class Destructor { public int x; public Destructor(int i) { this.x = i; } ~Destructor() { Console.WriteLine("Destruyendo El Objeto x :" + x); } public void Generador(int i) { Destructor ob = new Destructor(i); } } class Program { static void Main(string[] args) { int cuenta; Destructor obj = new Destructor(0); for (cuenta = 1; cuenta < 10; cuenta++) obj.Generador(cuenta); Console.WriteLine("Mierda! se van a destruir los objetos"); Console.ReadKey(); } }

using using using using

System; System.Collections.Generic; System.Linq; System.Text;

class puntos { public double x, y; public void puntostitle() { Console.WriteLine("Ingrese un par ordenado (x,y)"); Console.WriteLine("Valor en X"); x = double.Parse(Console.ReadLine()); Console.WriteLine("Valor en Y"); y = double.Parse(Console.ReadLine()); Console.WriteLine("(" + x + "," + y + ")"); } } class DemoPuntos { public static void Main() { puntos par1 = new puntos(); par1.puntostitle() ; Console.WriteLine("Presione una tecla para finalizar el proceso"); Console.ReadKey(); } } using using using using System; System.Collections.Generic; System.Linq; System.Text;

class demo { static void Main() { int[][] nodos = new int[4][]; nodos[0] = new int[7]; nodos[1] = new int[3];

nodos[2] = new int[2]; nodos[3] = new int[5]; int i, j; for (i = 0; i < nodos.Length; i++) { for (j = 0; j < nodos[i].Length; j++) nodos[i][j] = i * j + 70; } Console.WriteLine("Nodos: " + nodos.Length + "\n"); for (i = 0; i < nodos.Length; i++) { for (j = 0; j < nodos[i].Length; j++) { Console.Write("Uso de CPU en el nodo " + i + " CPU: " + j + ":"); Console.Write(nodos[i][j] + "%"); Console.WriteLine(); } Console.WriteLine(); } Console.ReadKey(); } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace ConsoleApplication2 { class irregular { static void Main() { int i; int[][] tabla = new int[3][]; tabla[0] = new int[4]; tabla[1] = new int[3]; tabla[2] = new int[5]; for (i = 0; i < 4; i++) tabla[0][i] = i; for (i = 0; i < 3; i++) tabla[1][i] = i; for (i = 0; i < 5; i++) tabla[2][i] = i; for (i = 0; i < 4; i++)

Console.Write(tabla[0][i] + "\t"); Console.WriteLine(); for (i = 0; i < 3; i++) Console.Write(tabla[1][i] + "\t"); Console.WriteLine(); for (i = 0; i < 5; i++) Console.Write(tabla[2][i] + "\t"); Console.WriteLine(); Console.ReadKey(); } } //2. using System; class demo1d { static void main() { int [] nums=newint[10]; Console.WriteLine("longitud:"+nums.Length); Console.ReadKey(); } } }

using using using using

System; System.Collections.Generic; System.Linq; System.Text;

class convertidor { static void Main() { Int64 num = 123456456321351321; Int64 digitosig = 0, numDigitos = 0; Int64[] n = new Int64[20]; String[] digitos = { "cero", "uno", "dos", "tres", "cuatro", "cinco", "seis", "siete", "ocho", "nueve" }; Console.WriteLine("Nmero: " + num); Console.WriteLine("Nmero en palabras: "); do { digitosig = num % 10; n[numDigitos] = digitosig; numDigitos++; num = num / 10; } while (num > 0); numDigitos--; for (; numDigitos >= 0; numDigitos--) Console.Write(digitos[n[numDigitos]] + " "); Console.ReadKey(); } }

using using using using

System; System.Collections.Generic; System.Linq; System.Text;

class convertidor { static void Main() { String[] cods = { "uno", "dos", "tres", "dos", "uno" }; foreach (String s in cods) { switch (s) { case "uno": Console.WriteLine(1); break; case "dos": Console.WriteLine(2); break; case "tres": Console.WriteLine(3); break; } } Console.ReadKey(); } }

using using using using

System; System.Collections.Generic; System.Linq; System.Text;

namespace esp1 { class uno { public void met1() { Console.WriteLine("Espacio de Nombre ESP1"); } } } namespace esp2 { class uno { public void met1() { Console.WriteLine("Espacio de Nombre ESP2"); } } } class ppal { public static void Main() { esp1.uno obj1 = new esp1.uno(); esp2.uno obj2 = new esp2.uno(); obj1.met1(); obj2.met1(); Console.ReadKey(); } }

using using using using

System; System.Collections.Generic; System.Linq; System.Text;

namespace esp1 { class uno { public void met1() { Console.WriteLine("Espacio de Nombre ESP1"); } } namespace esp3 { class uno { public void met1() { Console.WriteLine("Espacio de Nombre ESP3"); } } } } namespace esp2 { class uno { public void met1() { Console.WriteLine("Espacio de Nombre ESP2"); } } } class ppal { public static { esp1.uno obj1 esp2.uno obj2 esp1.esp3.uno obj1.met1();

void Main() = new esp1.uno(); = new esp2.uno(); obj3 = new esp1.esp3.uno();

obj2.met1(); obj3.met1(); Console.ReadKey(); } }

using using using using

System; System.Collections.Generic; System.Linq; System.Text;

//paso 1 class tareatrabajo { //paso 2 int a = 0, b = 0, c = 0, d = 0; // paso 3 int[] arreglo = new int[20]; //paso 4 public void metodo() { //paso 5 try { //paso 6.a for( int i = 0; i < 20; i++) { //paso 6.b Console.WriteLine("Ingrese un nmero entero"); i = Int32.Parse(Console.ReadLine()); //paso 6.c { if (arreglo[i] % 2 == 0) a = a + 1; else b = b + 1; //paso 6d } //paso 7 } //paso 8 int[] par = new int[a]; int[] impar = new int[b]; //paso 9a for (int m = 0; m < 20; m++) { //paso 9b-c (arreglo[] }

} Console.ReadKey(); }

using using using using

System; System.Collections.Generic; System.Linq; System.Text;

class Personas { public Personas() { Console.WriteLine("Cualquiuer Persona"); } public void leer() { Console.WriteLine("Para aprender debemos leer mucho"); } } class Estudiante { public Personas Estudiar(Personas P) { return P; } } class DemoP { public static void Main() { Personas alumno = new Personas(); Estudiante alumno2 = new Estudiante(); alumno2.Estudiar(alumno).leer(); Console.ReadKey(); } }

using using using using

System; System.Collections.Generic; System.Linq; System.Text;

class Personas { public Personas() { Console.WriteLine("Cualquiuer Persona"); } public void leer() { Console.WriteLine("Para aprender debemos leer mucho"); } } class Estudiante { public Personas Estudiar() { Personas alumno = new Personas(); return alumno; } } class DemoP { public static void Main() { Personas alumno = new Personas(); Estudiante alumno2 = new Estudiante(); alumno2.Estudiar().leer(); Console.ReadKey(); } }

//HERENCIA using using using using System; System.Collections.Generic; System.Linq; System.Text;

class claseuno { private string nombre; public void asignar() { Console.WriteLine("Ingerse su Nombre"); nombre = Console.ReadLine(); } public void imprimir() { Console.WriteLine("Su Nombre es: " + nombre); } } class clasedos : claseuno { private string apellido; public void asignar2() { Console.WriteLine("Ingerse su Apellido"); apellido = Console.ReadLine(); } public void imprimir2() { Console.WriteLine("Su Apellido es: " + apellido); } } class tres { public static void Main() { clasedos objeto2 = new clasedos(); objeto2.asignar(); objeto2.asignar2(); objeto2.imprimir(); objeto2.imprimir2(); Console.ReadKey();

} }

using using using using

System; System.Collections.Generic; System.Linq; System.Text;

class personas { string b; public personas() { Console.WriteLine("Hola desde el constructor de la clase 1"); } public personas(int a) { Console.WriteLine("Hola desde c2"); } public personas(int a, string b1) { b = b1; Console.WriteLine(b); } } class Productos : personas { public Productos(int x, string y): base(x, y) { Console.WriteLine("Hola desde el constructor de la clase 2"); } public Productos(int x): base(40) { Console.WriteLine("El valor de x es: "+x); } } class demo { public static void Main() { Productos objeto = new Productos(2); Productos objeto2 = new Productos(50); Productos objeto3 = new Productos(15, "Salu"); Console.ReadKey(); } }

class persona : ciudadano { public string nombre, apellido; public string info1() { return (nombre + " " + apellido + " " + pais + " " + nacionalidad); } } class Demo { public static void Main() { persona obj1 = new persona(); Console.WriteLine(obj1.saludo()); Console.WriteLine("Pone tu nombre maje"); obj1.nombre = Console.ReadLine(); Console.WriteLine("Pone tu apellido maje"); obj1.apellido = Console.ReadLine(); Console.WriteLine("Pone tu pas maje"); obj1.pais = Console.ReadLine(); Console.WriteLine("Pone tu nacionalidad maje"); obj1.nacionalidad = Console.ReadLine(); Console.WriteLine(obj1.info1()); Console.ReadKey() } }

using using using using

System; System.Collections.Generic; System.Linq; System.Text;

public class personas { string nombre; string apellido; int edad; public personas() { nombre = ""; apellido = ""; edad = 0; } public string minombre { get { return nombre; } set { nombre = value; } } public string miapellido { get { return apellido; } set { apellido = value; } } public int miedad { get

{ return edad; } set { if (value > 0) { edad = value; } } } }

public class exe { public static void Main() { personas obj = new personas(); Console.WriteLine("Ingrese su nombre"); Console.ReadLine(());

Console.ReadKey(); } }

Anda mungkin juga menyukai