Mostrando entradas con la etiqueta C#. Mostrar todas las entradas
Mostrando entradas con la etiqueta C#. Mostrar todas las entradas

sábado, 25 de junio de 2016

Diferencias entre C# y JAVA

Error al declara una matriz rectangular  en c# pensando que existe una sintaxis de C# propia de JAVA
JAVA
Una matriz rectangular (cuadrada) rectangular array, la puedo declara así
int [][] matrix = new int[n][n];

En C#  me sale un error: Invalid rank specifier: expected ',' or ']'

Necesariamente tengo que declararlo así una matriz cuadrada:
int [,] matrix = new int[n, n];

O sino
int [][] matrix = new int[n][];
e inicializar cada fila por separado, osea declarar un arreglo de arreglos (Jagged Array)

para 3 dimensiones seria por ejemplo
int[, ,] array1 = new int[4, 2, 3];

http://stackoverflow.com/questions/12567329/multidimensional-array-vs
www.functionx.com/csharp2/arrays/Lesson02b.htm

lunes, 23 de mayo de 2016

invertir una cadena C#

up vote283down voteaccepted
public static string Reverse( string s )
{
    char[] charArray = s.ToCharArray();
    Array.Reverse( charArray );
    return new string( charArray );
}
public static string Reverse(this string s)
    {
        return new String((s.ToCharArray().Reverse()).ToArray());
    }


C# Tips & Tricks: String Reversal

Unfortunately, C#'s string class is missing a Reverse() function, so here are three ways to reverse strings:

1. Manual Reversal

The most obvious way is to reverse a string by manually walking through it character for character and building a new string:
string input = "hello world";
string output = "";
for (int i = input.Length - 1; i >= 0; i--)
{
    output += input[i];
}
Note that if you take this approach in a serious program, you should use StringBuilder instead of string, since in the above code, a new temporary string is created each time you add a single character to the output string.

2. Array.Reverse()

The second way we can reverse a string is with the static Array.Reverse() method:
string input = "hello world";
char[] inputarray = input.ToCharArray();
Array.Reverse(inputarray);
string output = new string(inputarray);
First we convert the string to a character array, then we revert the array, and finally we construct a new string from the array.

3. LINQ

LINQ allows us to shorten string reversal into a one-liner:
string input = "hello world";
string output = new string(input.ToCharArray().Reverse().ToArray());
First the string is again converted to a char array. Array implements IEnumerable, so we can call LINQ's Reverse() method on it. With a call to ToArray() the resulting IEnumerable is then again converted to a char array, which is used in the string constructor.

For maximum convenience, we can create an extension method on string to do the reversal:
static class StringExtensions
{
    public static string Reverse(this string input)
    {
        return new string(input.ToCharArray().Reverse().ToArray());
    }
}
With this class in our code, we can now easily reverse any string:
Console.WriteLine("hello world".Reverse());

Please be aware however, that all of the above methods for string reversal only work with 16 bit Unicode characters, which fit into one char variable. If you need to reverse strings that include extended Unicode chars, for example chinese kanji, look here.

sábado, 21 de mayo de 2016

C#

Para determinar si un conjunto es subconjunto de otro
!b.Except(a).Any();
Operaciones en Conjuntos para ver si son iguales
HashSet<int> aSet = new HashSet<int>(a);// donde a es un int []
aSet.SetEquals(b);
aSet.IsProperSubSetOf(bSet);

Otro
a.Intersect(b).Count();
a.Union(b).Distinct().Count()

Ojo  Contains en un arreglo se habilita si esta using System.Linq
b.Contains(x)

viernes, 20 de mayo de 2016

eventos y delegados

  • Primero se declara el Delegado y después se declara el Evento
  • Se declaran en la clase que va a disparar el evento y en la zona reservada a la declaración de variables (campos) de la clase
  • y luego el/los metodos(s) que dispara el evento;

Ejemplo de Eventos y Delegados

La clase Empleado declara un evento "NombreCambiado" que se lanza cada vez que se cambia el atributo correspondiente al nombre del empleado. El evento tiene un manejador o delegado asociado (tipo del evento) "ActualizacionEventHandler" que declara una signatura para los métodos que pueden ser llamados para tratar el evento. En este caso, los métodos permitidos no devuelven nada (void) y deben tener un argumento de tipo string donde se pasará un mensaje a visualizar. En el método Main(), con la instrucción
MiEmpleado.NombreCambiado +=
new EjemploDelegados.ActualizacionEventHandler(NotificarCambioNombre);
se le indica al delegado que cuando se produzca el evento NombreCambiado se invoque al método "NotificarCambioNombre", método que respeta la firma declarada por el propio manejador de eventos.


*****************************************************************************

Program.cs



using System;

namespace EjemploDelegados
{
class Program
{
  public static void NotificarCambioNombre(string msg)
  {
      //imprimos mensaje aviso.
      Console.WriteLine("¡El nombre del empleado a cambiado!");
      Console.WriteLine(msg);
  }

  public static void Main(string[] args)
  {
      Empleado MiEmpleado = new Empleado("Ramiro");
      MiEmpleado.NombreCambiado +=
new EjemploDelegados.ActualizacionEventHandler(NotificarCambioNombre);
      Console.Write("Nombre empleado: ");
      MiEmpleado.setNombre(Console.ReadLine());

      Console.Write("Pulsa cualquier tecla para continuar . . . ");
      Console.ReadKey(true);
  }

}
}


Empleado.cs


using System;

namespace EjemploDelegados
{
public delegate void ActualizacionEventHandler(string msg); //YO OJO LO DECLARA FUERA DE LA CLASE

public class Empleado
{
//atributo
private string Nombre;

//... resto de atributos..

//declaración del evento
public event ActualizacionEventHandler NombreCambiado;

public Empleado(String Nombre)
{
this.Nombre=Nombre;
}

public void setNombre(string s)
{
//actualizar el atributo
string anteriorNombre=this.Nombre;
this.Nombre = s;

//lanzar el evento
this.NombreCambiado("Era "+anteriorNombre+"
                 y ahora es "+this.Nombre);
}

}
}

domingo, 26 de abril de 2015

viernes, 17 de octubre de 2014

javaserializar y subir archivos html y asp funciona

http://www.neuronasoft.net/2011/07/aspnet-subir-archivos-al-servidor-desde.html
http://panicoenlaxbox.blogspot.com/2010_11_01_archive.html

martes, 7 de octubre de 2014

jueves, 2 de octubre de 2014

QUERYSTRING PARAMETROS JAVASCRIPT Y C#

JAVASCRIPT
http://stackoverflow.com/questions/19491336/get-url-parameter-jquery
http://www.jquerybyexample.net/2012/06/get-url-parameters-using-jquery.html
http://www.w3schools.com/jsref/prop_loc_search.asp
http://w3lessons.info/2013/02/25/how-to-get-url-parameters-values-using-jquery/
C#
http://msdn.microsoft.com/es-es/library/system.web.httprequest.querystring%28v=vs.110%29.aspx
____

miércoles, 10 de septiembre de 2014

linq

http://kartones.net/blogs/sector7g/sintaxis-linq-union-intersect-y-except.aspx
http://danielggarcia.wordpress.com/2013/11/19/sentencias-en-linq-i-selecciones-simples-tipado-implicito-y-tipos-anonimos/

lunes, 8 de septiembre de 2014

domingo, 7 de septiembre de 2014

Encriptacion en C#

http://franciscogoita.blogspot.com/2014/09/encriptacion-y-desencriptacion-encrypt.html

miércoles, 27 de agosto de 2014

Tips de C#

Como obtener una solucion vacía
New Project -> Other Project Types -> Visual Studio Solutions -> Blank Solution
(produce el archivo .sln y sou)

Tab,Tab  para autocompletar

lunes, 21 de julio de 2014

Listas de tipos de proyectos en C#


INFO: List of known project type Guids

https://www.blogger.com/blogger.g?blogID=7595013619779102687#publishedposts

http://stackoverflow.com/questions/13600149/how-to-determinate-the-project-type-in-visual-studio