Skip to content

Instantly share code, notes, and snippets.

@pmarinr
Created January 10, 2014 18:35
Show Gist options
  • Save pmarinr/8359928 to your computer and use it in GitHub Desktop.
Save pmarinr/8359928 to your computer and use it in GitHub Desktop.
Ejemplo de Creación de una clase en C#
using System.IO;
using System;
class Coche
{
public Coche(string numero, string color, int ruedas, int gasoil){
this.marca = marca;
this.color = color;
this.ruedas = ruedas;
this.gasoil = gasoil;
}
public string marca;
public string color;
public int ruedas;
public int gasoil;
public string circular(int km){
this.gasoil = this.gasoil - km*6;
if(this.gasoil < 0){
this.gasoil = 0;
return "Falta Gasofa!!!";
}else{
return "Nos quedan "+this.gasoil+" litros";
}
}
public int repostar(int litros){
this.gasoil = this.gasoil + litros;
return this.gasoil;
}
public void pintar(string color){
this.color = color;
}
}
class Ejemplo{
static void Main(){
Coche mi_coche = new Coche("123123","Rojo",4,200 );
Console.WriteLine(mi_coche.gasoil);
Console.WriteLine(mi_coche.circular(20));
Console.WriteLine(mi_coche.gasoil);
Console.WriteLine(mi_coche.repostar(20));
mi_coche.circular(50);
Console.WriteLine(mi_coche.gasoil);
Console.WriteLine(mi_coche.ruedas);
Console.WriteLine(mi_coche.color);
mi_coche.pintar("Marron");
Console.WriteLine(mi_coche.color);
mi_coche.repostar(20);
Console.WriteLine(mi_coche.gasoil);
Console.WriteLine(mi_coche.circular(90));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment