'How to print 2 vertical lists next to each other in C#?
I was wondering how I would print 2 lists next to each other. For example:
- sentence: 1
- vowels: 3
etc...
How would I go about doing this?
Thanks in advance.
Solution 1:[1]
it was a little difficult to understand your requirements, but I think it may be the case where you could use a dictionary to solve your problem:
var dict = new Dictionary<string, int>{
{"Sentences",5},
{"Vowels",20},
{"Consonants",100},
{"Upper Case Letters",50}
};
foreach(var keyPair in dict){
Console.WriteLine(keyPair.Key + ": " + keyPair.Value);
}
Solution 2:[2]
I have figured out how to do this. It isn't a good way of doing it though. I converted my parameters list to equal string and then joined them together.
class Report
{
//Handles the reporting of the analysis
//Maybe have different methods for different formats of output?
//eg. public void outputConsole(List<int>)
// Variables
string text;
List<int> parameters;
public Report(string Text, List<int> Parameters)
{
// Text is what you inputed in manual text
text = Text;
// Parameters is the list of results from analyse
parameters = Parameters;
// Convert to a list to add to report list.
parameters.ToString();
}
public void OutputConsole()
{
// What they've inputed should be displayed.
Console.WriteLine("This is the text that you've inputed: " + text);
// The analysis should be reported. So, the numbers of sentences, etc
List<string> report = new List<string>() { "Sentences: " + parameters[0] , "Vowels: " + parameters[1], "Consonants: " + parameters[2], "Upper Case Letters: " + parameters[3], "Lower Case Letters: " + parameters[4] };
foreach (string reports in report)
{
Console.WriteLine(reports);
}
}
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Diego |
| Solution 2 | Daniel |
