오브젝트 유형 배열의 요소를 사용자 입력과 비교하려고합니다. 그렇게하기 위해 다음 코드를 작성했습니다. 코드에 오류가 없지만 예상대로 객체 비교가 작동하지 않는다는 것을 알았습니다. 미리 정의 된 배열과 사용자 입력을 비교하기 위해 코드를 편집하려면 어떻게해야합니까?C에서 오브젝트 배열 비교 #
class Program
{
static void Main(string[] args)
{
object[] Mathfunction = new object[] { '+','-','*','/'};
Console.WriteLine("Enter");
object input = Console.ReadLine();
for(int i=0;i<4;i++)
{
if (Mathfunction[i] == input)
{
Console.WriteLine("done");
Console.ReadLine();
}
}
}
4 개의 별도 'if'문을 사용하지 않는 이유는 무엇입니까? –
@ Okuma.Scott, 유지하고 이해하는 것이 더 힘들다면. 이것은 여기에 설명되어 있습니다. http://stackoverflow.com/questions/1554180/why-is-the-if-statement-considered-evil – codea