Продемонстровано три варіанти. Я вважаю за краще третій як самий стислий.
class Program {
static void Main(string[] args) {
string req = "PUT";
if ((new string[] {"PUT", "POST"}).Any(s => req.Contains(s))) {
Console.WriteLine("one.1.A"); // IS TRUE
}
req = "XPUT";
if ((new string[] {"PUT", "POST"}).Any(s => req.Contains(s))) {
Console.WriteLine("one.1.B"); // IS TRUE
}
req = "PUTX";
if ((new string[] {"PUT", "POST"}).Any(s => req.Contains(s))) {
Console.WriteLine("one.1.C"); // IS TRUE
}
req = "UT";
if ((new string[] {"PUT", "POST"}).Any(s => req.Contains(s))) {
Console.WriteLine("one.1.D"); // false
}
req = "PU";
if ((new string[] {"PUT", "POST"}).Any(s => req.Contains(s))) {
Console.WriteLine("one.1.E"); // false
}
req = "POST";
if ((new string[] {"PUT", "POST"}).Any(s => req.Contains(s))) {
Console.WriteLine("two.1.A"); // IS TRUE
}
req = "ASD";
if ((new string[] {"PUT", "POST"}).Any(s => req.Contains(s))) {
Console.WriteLine("three.1.A"); // false
}
Console.WriteLine("-----");
req = "PUT";
if (Array.IndexOf((new string[] {"PUT", "POST"}), req) >= 0) {
Console.WriteLine("one.2.A"); // IS TRUE
}
req = "XPUT";
if (Array.IndexOf((new string[] {"PUT", "POST"}), req) >= 0) {
Console.WriteLine("one.2.B"); // false
}
req = "PUTX";
if (Array.IndexOf((new string[] {"PUT", "POST"}), req) >= 0) {
Console.WriteLine("one.2.C"); // false
}
req = "UT";
if (Array.IndexOf((new string[] {"PUT", "POST"}), req) >= 0) {
Console.WriteLine("one.2.D"); // false
}
req = "PU";
if (Array.IndexOf((new string[] {"PUT", "POST"}), req) >= 0) {
Console.WriteLine("one.2.E"); // false
}
req = "POST";
if (Array.IndexOf((new string[] {"PUT", "POST"}), req) >= 0) {
Console.WriteLine("two.2.A"); // IS TRUE
}
req = "ASD";
if (Array.IndexOf((new string[] {"PUT", "POST"}), req) >= 0) {
Console.WriteLine("three.2.A"); // false
}
Console.WriteLine("-----");
req = "PUT";
if ((new string[] {"PUT", "POST"}.Contains(req))) {
Console.WriteLine("one.3.A"); // IS TRUE
}
req = "XPUT";
if ((new string[] {"PUT", "POST"}.Contains(req))) {
Console.WriteLine("one.3.B"); // false
}
req = "PUTX";
if ((new string[] {"PUT", "POST"}.Contains(req))) {
Console.WriteLine("one.3.C"); // false
}
req = "UT";
if ((new string[] {"PUT", "POST"}.Contains(req))) {
Console.WriteLine("one.3.D"); // false
}
req = "PU";
if ((new string[] {"PUT", "POST"}.Contains(req))) {
Console.WriteLine("one.3.E"); // false
}
req = "POST";
if ((new string[] {"PUT", "POST"}.Contains(req))) {
Console.WriteLine("two.3.A"); // IS TRUE
}
req = "ASD";
if ((new string[] {"PUT", "POST"}.Contains(req))) {
Console.WriteLine("three.3.A"); // false
}
Console.ReadKey();
}
}