You have two problems: you are calling a method in another class, so you can only call it using the fully qualified name, hence the class name and method name, unless you use using
to import . The other problem I preferred to solve this way is that this class and method should be static, even because they have no state, so you do not have to instantiate anything. In a more organized way it would look like this:
using static System.Console;
namespace testando {
class Program {
public static void Main() {
WriteLine("Escreva 1 para apresentar 'olá' na tela ou só <enter> para sair");
if (ReadLine() == "1") Pessoa.Falar();
}
}
public class Pessoa {
public static void Falar() => WriteLine("Olá meu nome é ninguém");
}
}
See working at .NET Fiddle . And no Coding Ground . Also put it in GitHub for future reference .
On the other hand, maybe I just wanted to put the method inside the same class, then I could call the method directly:
using static System.Console;
namespace testando {
class Program {
public static void Main() {
WriteLine("Escreva 1 para apresentar 'olá' na tela ou só <enter> para sair");
if (ReadLine() == "1") Falar();
}
public static void Falar() => WriteLine("Olá meu nome é ninguém");
}
}
See running on .NET Fiddle . And no Coding Ground . Also I placed GitHub for future reference .