Herramientas de usuario

Herramientas del sitio


highlevel:csharp:snippets

Diferencias

Muestra las diferencias entre dos versiones de la página.

Enlace a la vista de comparación

Ambos lados, revisión anterior Revisión previa
Próxima revisión
Revisión previa
highlevel:csharp:snippets [2009/11/28 10:10]
alfred
highlevel:csharp:snippets [2020/05/09 09:25] (actual)
Línea 30: Línea 30:
 System.Console.WriteLine("​Difference in days: {0} ", differenceInDays);​ System.Console.WriteLine("​Difference in days: {0} ", differenceInDays);​
 </​code>​ </​code>​
 +
  
  
Línea 56: Línea 57:
 </​code>​ </​code>​
  
 +=== Escribir en UTF8 ===
 +<code csharp>
 +System.IO.TextWriter tw = new System.IO.StreamWriter(
 +    new System.IO.FileStream(path + "​\\index.html",​ System.IO.FileMode.Create),​
 +    System.Text.Encoding.UTF8);​
 +tw.Write(body);​
 +tw.Close();
 +</​code>​
  
 ==== XML ==== ==== XML ====
Línea 78: Línea 87:
 } }
 </​code>​ </​code>​
 +
 ==== Expresiones regulares ==== ==== Expresiones regulares ====
 === Eliminar las tags de un texto === === Eliminar las tags de un texto ===
Línea 86: Línea 96:
     return Regex.Replace(text,​ @”<​(.|\n)*?>​”,​ string.Empty);​     return Regex.Replace(text,​ @”<​(.|\n)*?>​”,​ string.Empty);​
 } }
 +</​code>​
 +==== Descargar archivos de internet ====
 +<code csharp>
 +System.Net.WebClient wc = new System.Net.WebClient();​
 +wc.DownloadFile("​http://​url/​imagen.jpg",​ "​c:​\\img.jpg"​);​
 </​code>​ </​code>​
  
Línea 269: Línea 284:
 } }
 </​code>​ </​code>​
 +
 +
  
  
Línea 368: Línea 385:
 return buffer; return buffer;
 </​code>​ </​code>​
- 
  
  
Línea 498: Línea 514:
     s.Append(b.ToString("​x2"​).ToLower());​     s.Append(b.ToString("​x2"​).ToLower());​
 return s.ToString();​ return s.ToString();​
 +</​code>​
 +
 +=== Aplicación en background ===
 +<code csharp>
 +class Server {
 +    public void Start() {
 +        lock (this) {
 +            // Hacer algo
 +            Monitor.Wait(this);​
 +        }
 +    }
 +
 +    public void Stop()
 +    {
 +        lock (this)
 +        {
 +            // Hacer algo
 +            Monitor.PulseAll(this);​
 +        }
 +    }
 +
 +    static void Main(string[] args) {
 +        new Server().Start();​
 +    }
 +}
 </​code>​ </​code>​
  
Línea 516: Línea 557:
 conn.Close();​ conn.Close();​
 </​code>​ </​code>​
 +
  
  
Línea 529: Línea 571:
 con.Close();​ con.Close();​
 </​code>​ </​code>​
 +
highlevel/csharp/snippets.1259403005.txt.gz · Última modificación: 2020/05/09 09:24 (editor externo)