Last active
August 29, 2015 14:01
-
-
Save valdiney/2a5219414b2a1f831c0e to your computer and use it in GitHub Desktop.
Exemplo de uma class em C#
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Created by SharpDevelop. | |
* User: ruan | |
* Date: 09/05/2014 | |
* Time: 03:55 | |
* | |
* To change this template use Tools | Options | Coding | Edit Standard Headers. | |
*/ | |
using System; | |
namespace aula01 | |
{ | |
class Conta | |
{ | |
public string nome; | |
private double saldo; | |
public string saudaUsuario() | |
{ | |
return "Olá senhor " + this.nome; | |
} | |
public string deposito(double valor) | |
{ | |
this.saldo += valor; | |
return "Deposito realizado com sucesso"; | |
} | |
public string sacar(double valor) | |
{ | |
if(this.saldo >= valor) | |
{ | |
this.saldo -= valor; | |
return "Saque realizado. Você acabou de sacar R$ " + valor; | |
} | |
return "Seu saldo é de R$ " + this.saldo + " nao é suficiente para realizar o saque de R$ " + valor; | |
} | |
public void extrato() | |
{ | |
Console.WriteLine("Saldo atual é de R$ " + this.saldo); | |
} | |
} | |
class Program | |
{ | |
public static void Main(string[] args) | |
{ | |
var conta = new Conta(); | |
conta.nome = "Lucas Marinho"; | |
Console.WriteLine(conta.saudaUsuario()); | |
conta.deposito(100); | |
Console.WriteLine(conta.sacar(100)); | |
conta.extrato(); | |
Console.Write("Press any key to continue . . . "); | |
Console.ReadKey(true); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment