elhacker.net cabecera Bienvenido(a), Visitante. Por favor Ingresar o Registrarse
¿Perdiste tu email de activación?.

 

 


Tema destacado: Trabajando con las ramas de git (tercera parte)


+  Foro de elhacker.net
|-+  Programación
| |-+  Programación General
| | |-+  .NET (C#, VB.NET, ASP) (Moderador: kub0x)
| | | |-+  Programas en c#.net (Basico)
0 Usuarios y 1 Visitante están viendo este tema.
Páginas: 1 2 [3] Ir Abajo Respuesta Imprimir
Autor Tema: Programas en c#.net (Basico)  (Leído 99,773 veces)
Shell Root
Moderador Global
***
Desconectado Desconectado

Mensajes: 3.723


<3


Ver Perfil WWW
Re: Programas en c#.net (Basico)
« Respuesta #20 en: 14 Febrero 2010, 04:02 am »

Ami me funciona correctamente así:
Código
  1. using System;
  2.  
  3. namespace ConsoleApplication1
  4. {
  5.    class Program
  6.    {
  7.        static void Main(string[] args)
  8.        {
  9.            Console.BackgroundColor = ConsoleColor.Yellow;
  10.            Console.Write("Hola");
  11.            Console.Read();
  12.        }
  13.    }
  14. }


En línea

Por eso no duermo, por si tras mi ventana hay un cuervo. Cuelgo de hilos sueltos sabiendo que hay veneno en el aire.
[D4N93R]
Wiki

Desconectado Desconectado

Mensajes: 1.646


My software never has bugs. Its just features!


Ver Perfil WWW
Re: Programas en c#.net (Basico)
« Respuesta #21 en: 2 Junio 2010, 17:47 pm »

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


En línea

tomygrey

Desconectado Desconectado

Mensajes: 5


Ver Perfil
Re: Programas en c#.net (Basico)
« Respuesta #22 en: 5 Julio 2010, 22:42 pm »

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?
En línea

Lunfardo


Desconectado Desconectado

Mensajes: 568


Ver Perfil
Re: Programas en c#.net (Basico)
« Respuesta #23 en: 27 Octubre 2010, 01:47 am »

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
  1. using System;
  2. using System.Collections;
  3. public delegate bool filtro(int i);    
  4.  
  5.  
  6. class Filtros{
  7.  
  8.   public static bool Positivos(int i){
  9.     return (i>=0);
  10.  }
  11.  
  12.   public static bool Negativos(int i){
  13.  return (i<=0);
  14.  }
  15. }
  16.  
  17. class Filtador{
  18.    public static int[] Filtrador(int[] a, filtro fil){
  19.  
  20.        ArrayList aList = new ArrayList();
  21.  
  22.        for (int i = 0; i < a.Length; i++)
  23.        {
  24.            if (fil(a[i])) { aList.Add(a[i]); }
  25.  
  26.        }
  27.  
  28.  
  29.        return ((int[])aList.ToArray(typeof(int)));
  30.  
  31.  
  32.    }
  33.  
  34. }
  35.  
  36.  
  37. class hello
  38. {
  39.  
  40.    static void Main()
  41.    {
  42.      int[] a= {4,-4,6,-6,8,-8,10,-10};
  43.      int[] b;
  44.      filtro j;
  45.  
  46.      j = Filtros.Positivos;
  47.      b = Filtador.Filtrador(a,j);
  48.      foreach (int ca in b) Console.Write(ca + "  ");
  49.      Console.WriteLine();
  50.      j = Filtros.Negativos;
  51.      b = Filtador.Filtrador(a, j);
  52.  
  53.  
  54.      foreach (int ca in b) Console.Write(ca + "  ");
  55.  
  56.    }
  57.  
  58. }
« Última modificación: 27 Octubre 2010, 01:50 am por SmogMX » En línea

tkgeekshide

Desconectado Desconectado

Mensajes: 1


Ver Perfil
MATRICES C#
« Respuesta #24 en: 7 Abril 2012, 20:02 pm »

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?
En línea

Páginas: 1 2 [3] Ir Arriba Respuesta Imprimir 

Ir a:  
WAP2 - Aviso Legal - Powered by SMF 1.1.21 | SMF © 2006-2008, Simple Machines