1 import std.stdio, std.string; 2 3 void main() 4 { 5 bool find(T)(T[] all, T sub) 6 { 7 foreach(each; all) 8 { 9 if(each == sub) return true; 10 } 11 return false; 12 } 13 string[] arr=["stra","strb","strc"]; 14 int[] brr=[1,2,3]; 15 16 writeln(find(arr,"stra")); 17 writeln(find(arr,"strr")); 18 writeln(find(brr,3)); 19 writeln(find(brr,0)); 20 }
输出:
true
false
true
false