2010-02-27 5 views
0

내가 .. 기본 방법으로 클래스를 호출하고 싶 그리고이 오류를 받고 있어요 :의간단한 C# 프로그램으로 도움이 필요합니다!

코드 :

using System; 


namespace AddMinusDivideMultiply 
{ 
    class Program 
    { 
     public static int i, j; 

     public static void Main() 
     { 

      Console.Write("Please Enter The First Number :"); 
      string temp = Console.ReadLine(); 
      i = Int32.Parse(temp); 

      Console.Write("Please Enter The Second Number :"); 
      temp = Console.ReadLine(); 
      j = Int32.Parse(temp); 

      Minuz.minus(); // Here its generating an Error - Error 1 The name 'Minuz' does not exist in the current context  


     } 
    } 

    class Terms 
    { 
     public static void Add() 
     { 
      int add; 
      add = Program.i + Program.j; 
      Console.WriteLine("The Addition Of The First and The Second Number is {0}", add); 
     } 

    class Minuz 
    { 
     public static void Minus() 
     { 
     int minus; 
     minus = Program.i - Program.j; 
     Console.WriteLine("The Subraction Of The First and The Second Number is {0}", minus); 
     } 
    } 
    } 
} 
+2

어떤 오류가 발생합니까? –

답변

2

사례 C#에서 문제!

콜이 : 그것은 내부 약관 그래서 또한

Minuz.Minus(); 

, 당신의 괄호을 변경해야 다음 Class Minuz이 그래서 정말에 정의되지 않은 Class Terms 내부에 정의되어 있기 때문이다

class Terms 
{ 
    public static void Add() 
    { 
     int add; 
     add = Program.i + Program.j; 
     Console.WriteLine("The Addition Of The First and The Second Number is {0}", add); 
    } 
} 

class Minuz 
{ 
    public static void Minus() 
    { 
    int minus; 
    minus = Program.i - Program.j; 
    Console.WriteLine("The Subraction Of The First and The Second Number is {0}", minus); 
    } 
} 
1

사용하려는 컨텍스트

당신은 문제가 클래스 Minuz 클래스 Terms 내부 를 선언한다는 것입니다 Minuz

1

를 선언하기 전에 Terms의 정의를 닫지 않았고, 그것은 private입니다. 즉, Main 메서드에서 표시되지 않습니다.

를 해결하는 두 가지 방법이 있습니다

  • 클래스 Minuzinternal 또는 public 및 기회 Terms.Minuz.Minus()
  • 이동에 Minus 메소드의 호출 Terms 밖으로 클래스 Minuz의 선언을 확인가 클래스가 대신 네임 스페이스에서 선언되도록합니다.

또한, 다른 사람에 의해 지적 된대로; 메서드 이름의 대소 문자를주의하십시오. 수업 가시성이 수정되면 그것은 다음 문제가 될 것입니다.

1

Terms 클래스 내에 Minuz 클래스를 포함 시켰습니다. public class Minuz으로 설정 한 경우

Terms.Minuz.Minus(); 

으로 전화하면 오류를 해결할 수 있습니다. 하지만 아마도 Minuz 수업을 약관에서 제외하고 싶을 것입니다.

0

오타가없는 한 Terms 클래스의 닫기 대괄호가 없습니다. 귀하의 게시물에 현재 쓰여지는 방법은 다음과 같습니다 :

Terms.Minuz.Minus(); 
관련 문제