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:xtra2 [2010/03/16 08:24] alfred |
highlevel:csharp:xtra2 [2020/05/09 09:25] (actual) |
||
|---|---|---|---|
| Línea 4: | Línea 4: | ||
| ===== Sockets ===== | ===== Sockets ===== | ||
| * [[code:tools#sockets|Explicación de sockets]]. | * [[code:tools#sockets|Explicación de sockets]]. | ||
| + | |||
| ==== Creación de un servidor RAW ==== | ==== Creación de un servidor RAW ==== | ||
| <code csharp> | <code csharp> | ||
| Línea 27: | Línea 28: | ||
| } | } | ||
| } | } | ||
| + | </code> | ||
| + | Para enviar un "salto de línia" haremos: | ||
| + | <code csharp> | ||
| + | byte[] msg = System.Text.Encoding.ASCII.GetBytes(data + "\n\r"); | ||
| + | stream.Write(msg, 0, msg.Length); | ||
| </code> | </code> | ||
| Línea 119: | Línea 124: | ||
| ===== Configuración ===== | ===== Configuración ===== | ||
| + | |||
| Línea 183: | Línea 189: | ||
| IDictionary confTable = (IDictionary)System.Configuration.ConfigurationManager.GetSection("atm.ws/dbInfo"); | IDictionary confTable = (IDictionary)System.Configuration.ConfigurationManager.GetSection("atm.ws/dbInfo"); | ||
| string dataSource = (string)confTable["DataSource"]; | string dataSource = (string)confTable["DataSource"]; | ||
| + | </code> | ||
| + | |||
| + | |||
| + | |||
| + | ===== Programación declarativa con C# ===== | ||
| + | * [[code:best-practices#programacion_declarativa|Programación declarativa]] | ||
| + | ==== Métodos ==== | ||
| + | Podemos realizar un bucle ''foreach'' con el método ''List<T>.ForEac'' y una expresión lambda. | ||
| + | <code csharp> | ||
| + | using System; | ||
| + | using System.Collections.Generic; | ||
| + | |||
| + | class Example | ||
| + | { | ||
| + | static void Main() | ||
| + | { | ||
| + | new List<Int32> { 1, 2, 3 } | ||
| + | .ForEach(i => Console.WriteLine(i)); | ||
| + | } | ||
| + | } | ||
| + | </code> | ||
| + | De una forma parecida podemos sacar partido del delagado ''Action<T>'', el cual permite una funcion ''Action<Int32>'' el cual encaja con ''Console.WriteLine''. | ||
| + | <code csharp> | ||
| + | using System; | ||
| + | using System.Collections.Generic; | ||
| + | |||
| + | class Example | ||
| + | { | ||
| + | static void Main() | ||
| + | { | ||
| + | new List<Int32> { 1, 2, 3 } | ||
| + | .ForEach(Console.WriteLine); | ||
| + | } | ||
| + | } | ||
| + | </code> | ||
| + | También el método ''Enumerable.Range'': | ||
| + | <code csharp> | ||
| + | using System; | ||
| + | using System.Linq; | ||
| + | |||
| + | class Example | ||
| + | { | ||
| + | static void Main() | ||
| + | { | ||
| + | Int32 sum = Enumerable.Range(0, 99) | ||
| + | .Where(i => i % 2 == 0) | ||
| + | .Sum(); | ||
| + | Console.WriteLine(sum); | ||
| + | } | ||
| + | } | ||
| </code> | </code> | ||