Parámetros en C# - Por valor

El modo más sencillo de pasar el valor de una variable a un método se puede ver en el siguiente ejemplo: 

using System;class Parametros {

static void Main () {

int a = 2;

int b = 3;

int c = Suma (a, b);

Console.WriteLine (”{0} + {1} = {2}”, a, b, c);

}

static int Suma (int a, int b) {

return a + b; 

}

}

Se escriben el nombre de las variables a la hora de invocar el método, y cuando se define, la precedemos por su tipo. Así, al ejecutar el códi­go obtenemos: 

2 + 3 = 5

Leave a Reply