The structure is wrong for what you are trying to do, if, what you are trying to do is print the class functions in the Console.
You currently have the class structure:
class DevilHunter
{
public string Slogan() => Write("Devil May Cry!");
public virtual string Profissao() => Write("Caçar demônio");
}
The class DevilHunter
has two methods where they must return String
, however, the body of both methods call the method Console.Write
, and it does not return any value, just write in the Console that text.
If you want the methods to return the texts to use elsewhere (which is ideal), you should use properties in a way that returns the texts properly:
class DevilHunter
{
public string Slogan => "Devil May Cry!";
public virtual string Profissao => "Caçar demônio";
}
Or if you want them to continue being methods that write on the Console, change from string
for void
, since nothing comes back:
public void Slogan() => Write("Devil May Cry!");
However, the line above will not return anything and cannot be called to assign value to something.
Another mistake within your Main
is the call of Write
to another Write
. You need to specify a valid argument for the method Write
, and another Write
returns nothing.
Using properties, you can simply pass the property as String and it will work correctly. I also changed the method to WriteLine
so that there is a break in line between each profession.
class Program
{
static int Main(string[] args)
{
Dante dante = new Dante();
Nero nero = new Nero();
Nico nico = new Nico();
WriteLine(dante.Profissao); // public virtual string Profissao => "...";
WriteLine(nero.Profissao);
WriteLine(nico.Profissao);
return 0;
}
}
See working on .NET Fiddle.
The boot method depends on a few things, like the C# version and which compiler you’re using. If you are using a lower version than C# 7.1, this method will not work. You must use the signature static void Main(string[])
and not another, what changes is that you may or may not have arguments.
Signatures allowed to the input method, >= version 7.1, are:
public static void Main() { }
public static int Main() { }
public static void Main(string[] args) { }
public static int Main(string[] args) { }
public static async Task Main() { }
public static async Task<int> Main() { }
public static async Task Main(string[] args) { }
public static async Task<int> Main(string[] args) { }
In the documentation you can better understand about. In language reference also says about these signatures.
the main method shall be a
static X Main()
instatic class Program
where X is the return type, usuallyvoid
, but it may beint
also– Rovann Linhalis
@Rovannlinhalis this did not work
– Carlos A.
Just one observation: you don’t have any abstract class, and the doubt is not just about it... without knowing how you made the changes and where you are trying to compile also gets difficult. Being in the visual studio, you should have the Program static class, with the Main static method which is where the program will start
– Rovann Linhalis