There is a method in the Messages class called questionWhatisYourName() this method is called by another method called questionSurname() this method is called by the Main Method of the Class Program.
Is it possible to return the data from the questionWhatisYourName() into the questionSurname() with out calling it in the messages Class? Maybe I should pass it as an argument to the questionSurname() method?
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1
{
class TextEffects
{
public void drawLine() {
Console.WriteLine("------------------------------------");
}
public void drawLine(String linetype)
{
Console.WriteLine(linetype +
linetype + linetype + linetype + linetype + linetype + linetype + linetype + linetype + linetype
+ linetype + linetype + linetype + linetype + linetype + linetype + linetype + linetype);
}
}
class Messages
{
public void hello()
{
Console.WriteLine("Hello and welcome.");
}
public String questionWhatIsYourName()
{
Console.WriteLine("What is your name?");
String name = Console.ReadLine();
return name;
}
public void questionSurname()
{
String myname = this.questionWhatIsYourName();
Console.WriteLine(myname + " what is your surname?");
}
}
class Program
{
static void Main(string[] args)
{
TextEffects texteffects = new TextEffects();
Messages messages = new Messages();
texteffects.drawLine("+");
messages.hello();
messages.questionSurname();
}
}
}
Yes, pass it in as a string argument.
Call it like this: