C#

Anthony Anthony
Course by Anthony Anthony, updated 10 months ago Contributors

Description

Apuntes de lenguaje de programación C#

Module Information

No tags specified
Métodos con parámetros y sin parámetros   namespace Proyecto {     internal class Program     {         static void Main(string[] args)         {             Console.WriteLine("Estamos en el método main");             mostrarMensaje();             Console.WriteLine("Ya llegó el método");             Console.WriteLine($"Mostramos la devolución del valor del metodo Suma que es {Suma()}");             //TODO: Método con parametros             int numero1 = 15;             int numero2 = 25;             Console.WriteLine("La suma entre {0} y {1} es {2}",numero1, numero2, Sumar(numero1,numero2));             string mensaje = "Hola que hace";             recibirMensaje(mensaje);         }         //Metodo con parametro         public static int Sumar(int n1, int n2)         {             int sumar = n1 + n2;             return sumar;         }         public static void recibirMensaje(string mens)         {             Console.WriteLine(mens);         }         //TODO: Metodo void que no devuelve nada         public static void mostrarMensaje()         {             Console.WriteLine("Este es el método");         }         //TODO: Metodo int que devuelve un valor         public static int Suma()         {             int suma = 7 + 12;             return suma;         }     } }
Show less
No tags specified
Quiere decir que toda variable, método solo puede usarse dentro de su Scope ( {} ). Salvo que sea global
Show less
No tags specified
Es cuando se coloca métodos con el mismo nombre pero con distintos parámetros  namespace Proyecto {     internal class Program     {         static void Main(string[] args)         {             //TODO: Números aleatorios             Random ran = new Random();             Console.WriteLine(ran.Next());             //Devuelve valores de 0 al 5             Console.WriteLine(ran.Next(6));             //Devuelve valores en rango de esos dos números             Console.WriteLine(ran.Next(2,15));         }     } }
Show less
No tags specified
namespace Proyecto {     internal class Program     {         static void Main(string[] args)         {             Console.WriteLine("Cuantos clientes desea registrar");             int cR = int.Parse(Console.ReadLine());             for (int i = 1; i <= cR; i++)             {                 Console.WriteLine($"Registro de la persona ${i}:");                 Console.WriteLine("Ingrese el Nombre");                 string nombre = Console.ReadLine();                 Console.WriteLine("Ingrese la edad");                 int edad = int.Parse(Console.ReadLine());                 Console.WriteLine("Los datos del cliente registrado son: ");                 Console.WriteLine($"Cliente {i}: {nombre}, y tiene {edad} años");             }                   /// EJERCICIO 2   string[] diasSemana = { "Lunes", "Martes", "Miercoles", "Jueves", "Viernes", "Sabado", "Domingo" };  Console.WriteLine("Ingrese su día de descanso en número:");  int dia = int.Parse(Console.ReadLine());  if (dia >=1 && dia <=7)  {      Console.WriteLine($"Su día de descanso es: {diasSemana[dia - 1]}");  }  else  {      Console.WriteLine("Ingrese un número del 1 al 7");  }         }     } }        
Show less
No tags specified
namespace Proyecto {     internal class Program     {         static void Main(string[] args)         {             Console.WriteLine("Quieres entrar en el bucle while");             string confirmar = Console.ReadLine();             while (confirmar == "si")             {                 Console.WriteLine("Estamos dentro del bucle while");                 Console.WriteLine("¿Deseas continuar en el bucle while?");                 confirmar = Console.ReadLine();             }         }     } }
Show less
No tags specified
namespace Proyecto {     internal class Program     {         static void Main(string[] args)         {             string confirmar = "";             do             {                 Console.WriteLine("Estamos dentro del bucle while");                 Console.WriteLine("¿Deseas continuar en el bucle while?");                 confirmar = Console.ReadLine();             }             while (confirmar == "si");         }     } }
Show less
No tags specified
namespace Proyecto {     internal class Program     {         static void Main(string[] args)         {             string[] nombre = { "Pepe", "Enana", "Juan", "José" };             Console.WriteLine(nombre[2]);             int[] arrayEnteros = new int[1000];             for (int i = 0; i < arrayEnteros.Length; i++)             {                 arrayEnteros[i] = i + 1;                 Console.WriteLine(arrayEnteros[i]);             }         }     } }         // CALCULAR LA MEDIA DE NOTAS  namespace Proyecto {     internal class Program     {         static void Main(string[] args)         {             //TODO: Cuando se llaman a metodos se crea una nueva variable del mismo tipo y la pasa al metodo             double[] arrayMedia = new double[5];             RellenarArray(arrayMedia);             Console.WriteLine("La media de las notas es {0}", CalcularMedia(arrayMedia));         }         public static void RellenarArray(double[] array)         {             int i = 0;             do             {                 Console.WriteLine("Introduce la nota {0}", i + 1);                 double numeroMedia = double.Parse(Console.ReadLine());                 array[i] = numeroMedia;                 i++;             }             while (i < array.Length);         }         public static double CalcularMedia(double[] array)         {             double mediaTotal = 0;             for (int i = 0; i < array.Length; i++)             {                 mediaTotal += array[i];             }             return mediaTotal /= array.Length;         }     }     }
Show less
No tags specified
namespace Proyecto {     internal class Program     {         static void Main(string[] args)         {             //TODO: Cuando se llaman a metodos se crea una nueva variable del mismo tipo y la pasa al metodo             double[] arrayMedia = new double[5];             RellenarArray(arrayMedia);             Console.WriteLine("La media de las notas es {0}", CalcularMedia(arrayMedia));         }         public static void RellenarArray(double[] array)         {             int i = 0;             do             {                 Console.WriteLine("Introduce la nota {0}", i + 1);                 double numeroMedia = double.Parse(Console.ReadLine());                 array[i] = numeroMedia;                 i++;             }             while (i < array.Length);         }         public static double CalcularMedia(double[] array)         {             double mediaTotal = 0;             for (int i = 0; i < array.Length; i++)             {                 mediaTotal += array[i];             }             return mediaTotal /= array.Length;         }     }     }
Show less
No tags specified
//EJERCICIO 1 namespace Proyecto {     internal class Program     {         static void Main(string[] args)         {             // Paso 1: Crear un array con los números del 1 al 10             int[] numeros = new int[10];             for (int i = 0; i < 10; i++)             {                 numeros[i] = i + 1;             }             // Paso 2: Crear un array donde almacenar los números pares             // Usamos LINQ para filtrar los números pares             int[] numerosPares = numeros.Where(n => n % 2 == 0).ToArray();             // Paso 3: Mostrar los resultados             Console.WriteLine("Números del 1 al 10:");             foreach (var num in numeros)             {                 Console.Write(num + " ");             }             Console.WriteLine("\nNúmeros pares:");             foreach (var num in numerosPares)             {                 Console.Write(num + " ");             }       ///EJERCICIO 3  Console.WriteLine("Cuántos clientes desea registrar");  int clientes = int.Parse(Console.ReadLine());  string[] nombres = new string[clientes];  int[] edad = new int[clientes];  for (int i = 0; i < clientes; i++)  {      Console.WriteLine($"Ingrese el nombre del cliente {i+1}: ");      nombres[i] = Console.ReadLine();      Console.WriteLine($"Ingresa la edad del cliente {nombres[i]}: ");      edad[i] = int.Parse(Console.ReadLine());  }  for (int i = 0; i < clientes; i++)  {      Console.WriteLine($"El nombre del cliente es {nombres[i]} y tiene {edad[i]} años");  }         }     }     }
Show less
Show full summary Hide full summary