Skip to content

Instantly share code, notes, and snippets.

@auycro
Created October 27, 2020 00:44
Show Gist options
  • Save auycro/91476b0d316fff78c4b7d1f2d4574bea to your computer and use it in GitHub Desktop.
Save auycro/91476b0d316fff78c4b7d1f2d4574bea to your computer and use it in GitHub Desktop.
using System.Collections.Generic;
public class Program
{
public static void Main()
{
var test_data = Init();
test_data.ForEach((x)=>{
if (IsBothConditions(x)){
System.Console.WriteLine("baz");
} else if (IsContainsByThree(x)){
System.Console.WriteLine("bar");
} else if (IsMultiplyByThree(x)){
System.Console.WriteLine("foo");
} else {
System.Console.WriteLine(x);
}
});
}
public static List<int> Init(){
var result = new List<int>();
for(int i=0;i<50;i++){
result.Add(i+1);
}
return result;
}
public static bool IsMultiplyByThree(int input){
if ((input % 3) == 0){
return true;
}
return false;
}
public static bool IsContainsByThree(int input){
var cond = input.ToString();
if (cond.Contains(("3"))){
return true;
}
return false;
}
public static bool IsBothConditions(int input){
if (IsContainsByThree(input) && IsMultiplyByThree(input)){
return true;
}
return false;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment