1
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:

image

What could be happening? I'm using visual studio 2015

David Buck
  • 3,752
  • 35
  • 31
  • 35
  • What do you mean by it "doesn't show anything"? Can you post the screenshot of what it shows? – Mayur Ekbote Sep 27 '21 at 04:59
  • 1
    @MayurEkbote it's better to copy the output text from console and paste here instead of capturing a screenshot: [Why not upload images of code/errors when asking a question?](https://meta.stackoverflow.com/q/285551/995714) – phuclv Sep 27 '21 at 05:00
  • Wow tysm to everyone, I was looking at the wrong console, plus I had not declare it in the main function, is working now! – Claudia Velazquez Sep 27 '21 at 05:40
  • Please clarify your specific problem or provide additional details to highlight exactly what you need. As it's currently written, it's hard to tell exactly what you're asking. – Community Oct 05 '21 at 06:38

2 Answers2

4

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.

2

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?

Caius Jard
  • 72,509
  • 5
  • 49
  • 80