Reputation: 23
public class Account
{
private double balance;
public Account(double initBalance)
{
balance = initBalance;
this.balance = balance;
}
public double getBalance()
{
return balance;
}
public void deposit(double atm)
{
balance = atm + balance;
}
public void withdraw(double atm)
{
balance = balance - atm;
}
}
}
public class TestAccount
{
static void other()
{
Account objeto = new Account(50.0);
objeto.getBalance();
objeto.deposit(100.0);
objeto.withdraw(147.0);
Console.WriteLine(objeto.getBalance());
}
}
I'm trying to print the balance using writeline
, but the output doesn't show anything. I tried writing only text, but it only shows this:
What could be happening? I'm using visual studio 2015
Upvotes: 1
Views: 540
Reputation: 74605
I don't know if you'll find what you seek where you're looking. For starters that's the output from the compiler (see the drop down at the top of your screenshot that says "compiler", but even then you may not find your output in any of the other options either. If you're making a website type of project, then it might be in an item that mentions "web server". You might have an item called "Debug", which could contain the output- it might have to be done with Trace.WriteLine to show up
If you're making a console project then your output typically goes in a black window that appears when you press play but, depending on how you have things set up, it might disappear again when your program finishes, before you have a chance to read it. See How to stop C# console applications from closing automatically?
Upvotes: 2
Reputation: 75
To create a console application you need to have a Main function. You are not calling your other method from anywhere now. Main function is the starting point for your application.
namespace HelloWorld
{
class Hello
{
static void Main(string[] args)
{
System.Console.WriteLine("Hello World!");
}
}
}
See how the write line is inside the Main method? You have to write you code there and call methods or create instances there.
Upvotes: 4