Muestra las diferencias entre dos versiones de la página.
| Ambos lados, revisión anterior Revisión previa Próxima revisión | Revisión previa | ||
|
highlevel:csharp:snippets [2009/11/27 17:45] 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 469: | Línea 487: | ||
| string ConsoleOutput = process.StandardOutput.ReadToEnd(); | string ConsoleOutput = process.StandardOutput.ReadToEnd(); | ||
| return ConsoleOutput; | return ConsoleOutput; | ||
| + | } | ||
| + | </code> | ||
| + | === Encriptar en MD5 === | ||
| + | <code csharp> | ||
| + | using System; | ||
| + | using System.Text; | ||
| + | using System.Security.Cryptography; | ||
| + | ... | ||
| + | public string EncodePassword(string originalPassword) | ||
| + | { | ||
| + | Byte[] originalBytes; | ||
| + | Byte[] encodedBytes; | ||
| + | MD5 md5 = new MD5CryptoServiceProvider(); | ||
| + | originalBytes = ASCIIEncoding.Default.GetBytes(originalPassword); | ||
| + | encodedBytes = md5.ComputeHash(originalBytes); | ||
| + | return BitConverter.ToString(encodedBytes); | ||
| + | } | ||
| + | </code> | ||
| + | ... o ... | ||
| + | <code csharp> | ||
| + | System.Security.Cryptography.MD5CryptoServiceProvider x = new System.Security.Cryptography.MD5CryptoServiceProvider(); | ||
| + | byte[] bs = System.Text.Encoding.UTF8.GetBytes(text); | ||
| + | bs = x.ComputeHash(bs); | ||
| + | System.Text.StringBuilder s = new System.Text.StringBuilder(); | ||
| + | foreach (byte b in bs) | ||
| + | s.Append(b.ToString("x2").ToLower()); | ||
| + | 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 488: | Línea 557: | ||
| conn.Close(); | conn.Close(); | ||
| </code> | </code> | ||
| + | |||
| Línea 501: | Línea 571: | ||
| con.Close(); | con.Close(); | ||
| </code> | </code> | ||
| + | |||