Programas en c#.net (Basico)

<< < (5/5)

Shell Root:
Ami me funciona correctamente así:
Código
using System;
 
namespace ConsoleApplication1
{
   class Program
   {
       static void Main(string[] args)
       {
           Console.BackgroundColor = ConsoleColor.Yellow;
           Console.Write("Hola");
           Console.Read();
       }
   }
}

[D4N93R]:
Código
  1:  using System;
  2:  using System.Collections.Generic;
  3:  using System.Text;
  4:  using System.Net.NetworkInformation;
  5:  
  6:  namespace D4N93R.Traceroute
  7:  {
  8:      //Delegado para los eventos del Traceroute
  9:      public delegate void TracertEventHandler(object sender, TracertEventArgs e);
 10:      
 11:      public class Tracert
 12:      {
 13:          int     m_timeout   = 0;
 14:          string  m_host      = "";
 15:          int     m_maxHops   = 0;
 16:  
 17:          public event TracertEventHandler EchoReceived;
 18:          public event TracertEventHandler ErrorReceived;
 19:          public event TracertEventHandler TracertCompleted;
 20:  
 21:          public Tracert(string host, int TimeOut, int maxHops)
 22:          {
 23:              m_host = host;
 24:              m_timeout = TimeOut;
 25:              m_maxHops = maxHops;
 26:          }
 27:          public void Start()
 28:          {
 29:              PingReply reply;
 30:              Ping pinger = new Ping();
 31:              PingOptions options = new PingOptions();
 32:  
 33:              //Con esto le decimos al paquete que nada más salte un equipo.
 34:              options.Ttl = 1;
 35:  
 36:              options.DontFragment = true;
 37:  
 38:              byte[] buffer = Encoding.ASCII.GetBytes("Algo de datos");
 39:              try
 40:              {
 41:                  do
 42:                  {
 43:                      //Tiempo antes del comando
 44:                      DateTime start = DateTime.Now;
 45:  
 46:                     //Mandamos el ping
 47:                      reply = pinger.Send(m_host,
 48:                                          m_timeout,
 49:                                          buffer,
 50:                                          options);
 51:  
 52:                      //Restamos la diferencia de tiempo para conocer la latencia.
 53:                      long milliseconds = DateTime.Now.Subtract(start).Milliseconds;
 54:                      if ((reply.Status == IPStatus.TtlExpired)
 55:                         || (reply.Status == IPStatus.Success))
 56:                      {
 57:                          //Damos respuesta en caso de que encontremos un host
 58:                          //o que se haya finalizado el proceso.
 59:                          OnEchoReceived(reply, milliseconds, options.Ttl);
 60:                      }
 61:                      else
 62:                      {
 63:                          OnErrorReceived(reply, milliseconds);
 64:                      }
 65:                      options.Ttl++;
 66:  
 67:                     //Mientras no haya terminado, es decir, no sea Success
 68:                     //seguimos mandando ping con un TTL aumentado.
 69:        
 70:                     // Notemos que cuando la resuesta es Success
 71:                     //es porque el paquete llego al destino
 72:                  } while ((reply.Status != IPStatus.Success)
 73:                          && (options.Ttl < m_maxHops));
 74:              }
 75:              catch (PingException pex)
 76:              {
 77:                  //Acá pueden implementar algo en caso de algun error.
 78:                  throw pex.InnerException;
 79:              }
 80:              finally
 81:              {
 82:                  if (TracertCompleted != null)
 83:                      TracertCompleted(this, new TracertEventArgs(null, 0, 0));
 84:              }  
 85:          }
 86:  
 87:  
 88:          //Manejo de los eventos.
 89:          private void OnErrorReceived(PingReply reply, long milliseconds)
 90:          {
 91:              InvokeErrorReceived(reply, milliseconds);
 92:          }
 93:  
 94:          private void OnEchoReceived(PingReply reply, long milliseconds, int ttl)
 95:          {
 96:              InvokeEchoReceived(reply, milliseconds, ttl);
 97:          }
 98:          public void InvokeEchoReceived(PingReply reply, long milliseconds, int ttl)
 99:          {
100:              if (EchoReceived != null)
101:                  EchoReceived(this, new TracertEventArgs(reply, milliseconds,ttl));
102:          }
103:          public void InvokeErrorReceived(PingReply reply, long milliseconds)
104:          {
105:              if (ErrorReceived != null)
106:                  ErrorReceived(this, new TracertEventArgs(reply, milliseconds,0));
107:          }
108:      }
109:  }
 

tomygrey:
Weno soy iniciado en estos temas de programacion en c sharp, stoy studiando en un instituo, y kisiera que me ayudaras a resolver un problema
De una lista de enteros de un vector me pide capturar dos elementos menores ingresados por teclado. Lo estado intentando y solo puedo encontra el mas minimo, pero el sgte menor como lo capturo?

Lunfardo:
bueno ,dejo un ejemplo bastante basico, pero creo que deja una idea clara de como usar delegados,

el programa no hace nada del otro mundo ,solo "filtra" arreglos, espero que puedan abstraer la idea
Código
using System;
using System.Collections;
public delegate bool filtro(int i);    
 
 
class Filtros{
 
  public static bool Positivos(int i){
    return (i>=0);
 }
 
  public static bool Negativos(int i){
 return (i<=0);
 }
}
 
class Filtador{
   public static int[] Filtrador(int[] a, filtro fil){
 
       ArrayList aList = new ArrayList();
 
       for (int i = 0; i < a.Length; i++)
       {
           if (fil(a[i])) { aList.Add(a[i]); }
 
       }
 
 
       return ((int[])aList.ToArray(typeof(int)));
 
 
   }
 
}
 
 
class hello
{
 
   static void Main()
   {
     int[] a= {4,-4,6,-6,8,-8,10,-10};
     int[] b;
     filtro j;
 
     j = Filtros.Positivos;
     b = Filtador.Filtrador(a,j);
     foreach (int ca in b) Console.Write(ca + "  ");
     Console.WriteLine();
     j = Filtros.Negativos;
     b = Filtador.Filtrador(a, j);
 
 
     foreach (int ca in b) Console.Write(ca + "  ");
 
   }
 
}

tkgeekshide:
Hola necesito ayuda, necesito hace en C# una matriz...la cual con 1 textbox voy ingresando los numero (tiene que ser una matriz de 4x4) y despues al elegir en el radiobutom por ejemplo la opcion suamar, que sume las matrizes ...Me ayudas?

Navegación

[0] Índice de Mensajes

[*] Página Anterior