✅ Creating a typewriter function that takes two optional arguments
public static void TypeWriter(List<string> input = null, string otherInput = null){ if (otherInput) { foreach (string line in input) { for (int i = 0; i < line.Length; i++) { Console.Write(line[i]); Thread.Sleep(80); } } } else { for (int i = 0; i < otherInput.Length; i++) { Console.Write(input[i]); Thread.Sleep(80); } }}
public static void TypeWriter(List<string> input = null, string otherInput = null){ if (otherInput) { foreach (string line in input) { for (int i = 0; i < line.Length; i++) { Console.Write(line[i]); Thread.Sleep(80); } } } else { for (int i = 0; i < otherInput.Length; i++) { Console.Write(input[i]); Thread.Sleep(80); } }}
I'm trying to write my own function that mimic the typewriter functionality that checks whether one or the other parameter has a value to use and if so, then execute the correct part of the if or else statement. I'm not understanding what I'm doing wrong here as it does not like
if (otherInput)
if (otherInput)
nor does it like
if (otherInput.Equals(null))
if (otherInput.Equals(null))
so what am I supposed to put on that line, or how can I better check if the list is empty, then execute the else statement otherwise execute the if statement? Thanks