// Ex2 static string JoinThree(string a, string b, string c, StringJoin x) { string newString = x(a, b); newString = x(newString, c); return(newString); }
static void Main(string[] args) { List <string> strings = new List <string> { "a", "b", "c", "d" }; List <int> numbers = new List <int> { 1, 2, 3, 4 }; StringJoin stringJoin = (a, b) => a + b; StringJoin stringJoinWithDot = (a, b) => a + "." + b; StringJoin stringJoinOnlyLast = (a, b) => b; Console.WriteLine(stringJoin("Hello ", "Delegates")); Console.WriteLine(JoinThree("a", "b", "c", stringJoin)); Console.WriteLine(JoinThree("a", "b", "c", stringJoinWithDot)); Console.WriteLine(JoinThree("a", "b", "c", stringJoinOnlyLast)); Console.WriteLine(); Console.WriteLine(JoinAllStrings(strings, stringJoin)); Console.WriteLine(JoinAllStrings(strings, stringJoinWithDot)); Console.WriteLine(JoinAllStrings(strings, stringJoinOnlyLast)); Console.WriteLine(); Join <int> numberJoin = (a, b) => a + b; Join <int> numberJoinMultiply = (a, b) => a * b; Join <string> stringJoins = (a, b) => a + "." + b; Console.WriteLine(JoinList <int>(numbers, numberJoin)); Console.WriteLine(JoinList <int>(numbers, numberJoinMultiply)); Console.WriteLine(JoinList <string>(strings, stringJoins)); }
public string JoinThree(string str1, string str2, string str3, StringJoin join) { string newString; newString = join(str1, str2); newString = join(newString, str3); return(newString); }
public string JoinAllStrings(List <string> stringList, StringJoin joiner) { for (int i = 1; i < stringList.Count; i++) { stringList[0] = joiner(stringList[0], stringList[i]); } return(stringList[0]); }
public string JoinAllStrings(List <string> strings, StringJoin join) { string newString = strings[0]; for (int i = 1; i <= strings.Count - 1; i++) { newString = join(newString, strings[i]); } return(newString); }
// Opgave 4 // Define a method JoinAllStrings, parameterized by a list of strings and a // StringJoin, which joins all strings in the list from left to right. For example: public static string JoinAllStrings(List <string> strings, StringJoin str) { var res = ""; while (strings.Count > 1) { strings[0] = str(strings[0], strings[1]); strings.RemoveAt(1); } return(strings[0]); }
static int Main() { StringJoin test = new StringJoin(); TestFramework.BeginTestCase("String.Join"); if (test.RunTests()) { TestFramework.EndTestCase(); TestFramework.LogInformation("PASS"); return(100); } else { TestFramework.EndTestCase(); TestFramework.LogInformation("FAIL"); return(0); } }
// Ex3 static string JoinAllStrings(List <string> strings, StringJoin x) { bool isFirst = true; string newString = ""; foreach (string item in strings) { if (isFirst) { newString = item; } else { newString = x(newString, item); } isFirst = false; } return(newString); }
static int Main() { StringJoin test = new StringJoin(); TestFramework.BeginTestCase("String.Join"); if (test.RunTests()) { TestFramework.EndTestCase(); TestFramework.LogInformation("PASS"); return 100; } else { TestFramework.EndTestCase(); TestFramework.LogInformation("FAIL"); return 0; } }
public void Merge(StringJoin Group) { this.intermediateResult.Append(Group.intermediateResult); }
public string JoinThree(string s1, string s2, string s3, StringJoin joiner) { return(joiner(joiner(s1, s2), s3)); }
private string JoinAllStrings(List <string> l, StringJoin f, int startIndex) => JoinAll(l, (v1, v2) => f(v1, v2), startIndex);
public string JoinAllStrings(List <string> l, StringJoin f) => JoinAllStrings(l, f, 0);
public string Join3(string s1, string s2, string s3, StringJoin f) => f(s1, f(s2, s3));
// Opgave 3 public static string Join3(string l, string r, string w, StringJoin str) { string res = str(l, r); return(str(res, w)); }