Coder Social home page Coder Social logo

csharp-examples's Introduction

Ejercicios de Programación en C#

Estos ejercicios están organizados por nivel: básico e intermedio, y por tema. Cada uno de los ejemplos existe en un proyecto individual de Visual Studio.

En cada nivel la carpeta "Inicial" contiene la versión inicial de cada proyecto.

Temas C# Básico

  • Fundamentos de C#
  • Tipos predefinidos y control de flujo
  • Clases y Objetos
  • Control de Acceso
  • Arreglos y IEnumerable
  • Herencia
  • Polimorfismo

Temas C# Intermedio

  • Delegados, Lambdas y Eventos
  • Excepciones
  • Strings
  • Manejo de archivos
  • Genéricos
  • Colecciones
  • LINQ

Algunos ejemplos

Constructores

public class CuentaBancaria
{
    public string NoCuenta { get; set; }
    public string Usuario { get; set; }
    public decimal Saldo { get; set; }       

    public CuentaBancaria(string noCuenta)
    {
        NoCuenta = noCuenta;
    }

    public CuentaBancaria(string noCuenta, string usuario)
        : this(noCuenta)
    {           
        Usuario = usuario;
    }

    public CuentaBancaria(string noCuenta, string usuario, decimal saldo)
        : this(noCuenta, usuario)
    {            
        Saldo = saldo;
    }

    // Constructor vacío
    public CuentaBancaria() { }
}

Clase Array

int[] list = { 34, 72, 13, 44, 25, 30, 10 };
int[] temp = new int[list.Length];

// Genera una copia del arreglo
Array.Copy(list, temp, list.Length);

Console.Write("Arreglo Original: ");
MostrarArreglo(list);

// invierte el arreglo
Array.Reverse(temp);
Console.Write("Arreglo Invertido: ");
MostrarArreglo(temp);

// ordena el arreglo
Array.Sort(list);
Console.Write("Arreglo Ordenado: ");
MostrarArreglo(list);

Strings

string cadena = "Esta es una cadena de prueba";
Console.WriteLine(cadena);
Console.WriteLine("Tamaño: " + cadena.Length);
Console.WriteLine("Mayúsculas: " + cadena.ToUpper());
Console.WriteLine("Minúsculas: " + cadena.ToLower());
// Uso de Replace para quitar espacios
Console.WriteLine("Replace: " + cadena.Replace(" ", ""));
Console.WriteLine("Carácter en índice 0: " + cadena[0]);
Console.WriteLine("Carácter en índice 1: " + cadena[1]);
// Subcadena de 8 caracteres a partir del índice 1
Console.WriteLine("Substring (1-8): " + cadena.Substring(1, 8)); 

Escritura de archivos

using (var writer = new StreamWriter("prueba.txt"))
{
    Console.Write("Escritura a un archivo\nEscribe un mensaje: ");
    string str =  Console.ReadLine();
    while (String.Compare(str, "salir", true) != 0)
    {
        writer.WriteLine(str);
        Console.Write("Escribe un mensaje: ");
        str = Console.ReadLine();
    }                    
}

LINQ

List<int> numeros = new List<int> { 2, 9, 5, 0, 3, 7, 1, 4, 8, 5 };

// Obtiene una lista solo con los elementos mayores a 4
var filtered = numeros.Where(n => n > 4);

// la cláusula order by ordena los valores originales en orden ascendente            
var sorted = numeros.OrderBy(n => n);

// ordena los resultados filtrados en orden descendente            
var sortFilteredResults = filtered.OrderByDescending(n => n);

csharp-examples's People

Contributors

enrique7mc avatar

Watchers

James Cloos avatar Carlos Tangarife avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.