Can anyone please help me with this?
It should be a ConsoleApp which asks for the first and the last name. From the all name, it should generate 4 characters. I have to provide different possible combinations of the strings (e.g. 1. and 3. char of fn and 2. 3. char of ln ...) The Algorithm should be capable of providing all possible combinations of 4 characters where 2 are from the first name and 2 of the last name.
Till now I did only the combinations of 2 for the first name and the last name.
static void Main(string[] args)
{
Console.WriteLine("Enter your first name");
string firstName = Console.ReadLine();
Console.WriteLine("Enter your last name");
string lastName = Console.ReadLine();
string[] result = GetAllCombinations(firstName);
string[] code = GetAllCombinations(lastName);
PrintTheCombinations(result);
PrintTheCombinations(code);
}
private static void PrintTheCombinations(string[] list)
{
foreach (var results in list)
{
Console.WriteLine(results);
}
}
private static string[] GetAllCombinations(string word)
{
int arraylength = word.Length * word.Length;
var ret = new string[arraylength];
for (int i = 0; i < word.Length; i++)
{
for (int j = 0; j < word.Length; j++)
{
ret[i * word.Length + j] = string.Concat(word[i], word[j]);
}
}
return ret;
}
Now I need to print the 4 characters, 2 of the fn and 2 of the ln, but I'm stuck. Hope you guys understand what i mean