using System.Collections.Generic;
public static void Main()
Console.WriteLine(Message("filename", 1, "Dog"));
Console.WriteLine(Message("filename", 2, "Dog", "Cat"));
Console.WriteLine(Message("filename", 3, "Dog", "Cat", "Mouse"));
Console.WriteLine(Message("filename", 4, "Dog", "Cat", "Mouse", "Spider"));
Console.WriteLine(Message("filename", 5, "Dog", "Cat", "Mouse", "Spider", "Mongoose"));
public static string Message(string filename, int rowNumber, string field, params string[] otherFields)
=> Message3(filename, rowNumber, field, otherFields);
public static string Message1(string filename, int rowNumber, string field, params string[] otherFields)
switch (otherFields.Length)
fields = $"one of {field} or {otherFields[0]}";
fields = $"one of {field}, {string.Join(", ", otherFields.Take(otherFields.Length - 1))} or {otherFields.Last()}";
return $"In the file {filename} it is mandatory to have {fields}. This happened on row {rowNumber}";
public static string Message2(string filename, int rowNumber, string field, params string[] otherFields)
var fields = (otherFields.Length == 0)
: "one of " + string.Join(", ", otherFields.Prepend(field).Take(otherFields.Length)) + " or " + otherFields.Last();
return $"In the file {filename} it is mandatory to have {fields}. This happened on row {rowNumber}";
public static string Message3(string filename, int rowNumber, string field, params string[] otherFields)
string fields = (otherFields.Length == 0)
: (otherFields.Length == 1)
? $"one of {field} or {otherFields[0]}"
: $"one of {field}, {string.Join(", ", otherFields.Take(otherFields.Length - 1))} or {otherFields.Last()}";
return $"In the file {filename} it is mandatory to have {fields}. This happened on row {rowNumber}";