ejmtv
ejmtv

Reputation: 198

How to include a method in a string.format syntax inside a console.writeline in C#?

I have a method that displays something like:

public void display(){

Console.Writeline("Message");
}

And I should include it in the console.writeline that use string.format (the one inside <<>> is just how should it look:

int CodeName = 52;
Console.WriteLine("Mutant Name: {0} ------ Message: {1}", CodeName, <<dispplay()>>);

Upvotes: 0

Views: 56

Answers (1)

Koby Douek
Koby Douek

Reputation: 16693

Try calling the display method by making it return a value.

Like this:

public string display() 
{
    return "Message";
}

int CodeName = 52;

Console.WriteLine(string.Format("Mutant Name: {0} ------ Message: {1}", CodeName, display()));

Upvotes: 3

Related Questions