2012-12-14 2 views
2

'C# 및 XAML로 Windows 8 용 응용 프로그램 만들기.컴파일러에서 메서드 이름을 찾을 수 없습니다

나는 AppNamespace라는 네임 스페이스 내에서 두 개의 클래스를 정의했다,이 클래스 중 하나는 그것의 생성자 내에서 세 가지 차원 부울 배열을 :

public class Solver 
    { 
     // Board is a class also in this namespace but I don't think the issue is 
     //there, so I've omitted it's definition 
     private Board current; 

     // You can see that the class clearly DOES take a parameter of the same type 
     // as the array "content" (which is defined later) 
     public Solver (bool[, ,] initial) 
     { 
      // The parameter is then used to construct a "Board" class within the 
      // "Solver" class. 
      current = new Board(initial); 
     } 

     // Several methods within the class 
    } 

그래서 정의는 위에서 볼 수 있습니다.

그러면 'NewPage.xaml'이라는 gridapp에 새 페이지를 만들고 그 페이지에 배열 내의 값을 조작하는 일부 텍스트 상자가 있습니다. (여기서 문제가되지 않는 것 같습니다)

버튼을 클릭하면 'NewPage.xaml.cs'에서 클래스에 인스턴스를 생성하고 클래스 내에서 메소드를 실행해야합니다. 아래와 같이 "NewPage.xaml.cs"의 상단 I는 세 가지 차원 배열을 정의

// Declare the namespace where the class "Solver" is situated 
    using App.Classes; 

    namespace App 
    { 
     // So below is the C# part of the page "PuzzleSolver" 
     public sealed partial class PuzzleSolver : App.Common.LayoutAwarePage 
     { 
      // Create an array called content 
      bool[, ,] content = new bool[9, 9, 9]; 

      public PuzzleSolver() 
      { 
       this.InitializeComponent(); 

       //Set every cell of the created content array to true 
       for (int i = 0; i <= 8; i++) 
       { 
        for (int j = 0; j <= 8; j++) 
        { 
         for (int k = 0; k <= 8; k++) 
         { 
          content[i, j, k] = true; 
         } 
        } 
       } 
      } 

     /* There are some methods which change information in the array "Content" based on the 
     stuff input into the XAML textboxes on the page. */ 


     // The below method is invoked when a XAML Button is clicked on the page 
     // and I intend it to create a "Solver" object, using the "content" array 
     // from this page as a parameter 
     private void Button_Click_1(object sender, RoutedEventArgs e) 
     { 
     // So now I create the and pass in the "content" array 
     Solver newSolve = new Solver(content); 

     newSolve.Solve(); 
     } 
} 

문제는 컴파일러가 "클래스 이름은"클래스임을 인식이지만, 그렇지 않은 것을 말한다 1 매개 변수를 사용하는 생성자가 있고 또한 다음과 같이 말합니다 :

"ProjectName.className에"met HOD 및 은 더 확장 방법은 ProjectName.className를 볼 수 있습니다 유형 의 첫 번째 인수를 받아들이는 "방법"(당신은 사용 지시문 또는 어셈블리 참조가 "실종되지

내 문제는이 정보를 어디에서 사람이 식별 할 수 ?

나는이 다른 네임 스페이스 선언, "Solver.xaml.cs"에 먼저 선언을 보여주기 위해 편집 한 :

using System; 
using System.Collections.Generic; 
using System.IO; 
using System.Linq; 
using Windows.Foundation; 
using Windows.Foundation.Collections; 
using Windows.UI.Xaml; 
using Windows.UI.Xaml.Controls; 
using Windows.UI.Xaml.Controls.Primitives; 
using Windows.UI.Xaml.Data; 
using Windows.UI.Xaml.Input; 
using Windows.UI.Xaml.Media; 
using Windows.UI.Xaml.Navigation; 
using App.Classes; 

이제 선언을 "Solver.xaml"에 :

<common:LayoutAwarePage 
    x:Name="pageRoot" 
    x:Class="App.Solver" 
    DataContext="{Binding DefaultViewModel, RelativeSource={RelativeSource Self}}" 
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
    xmlns:local="using:App" 
    xmlns:common="using:App.Common" 
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
    mc:Ignorable="d"> 

    <Page.Resources> 
     <x:String x:Key="PageName">Solver</x:String> 
    </Page.Resources> 
+1

className 정의에 정의 된 method()가 표시되지 않습니다. 전화하려는 방법이 있는지 확인하십시오. –

+0

'3 차원 부울 배열'- 내 머리가 아파요 .-) – leon

+0

@ScottChapman 죄송합니다. 예, 메소드를 정의했지만 클래스 자체가 너무 길고 복잡하기 때문에 그 내용을 버렸습니다.하지만 문제는 아니라고 생각했습니다. 이것이 C#과 함께 할 것인가? – GArchitech

답변

2

인스턴스를 선언 할 때 변수 이름으로 object을 사용하고 있습니다. object이 예약 된 키워드 (항상 System.Object을 의미) 때문에

className object = new className(content); 
object.method(); 

이 컴파일러가 혼동됩니다.

더 나은 이름을 사용해야합니다. 때문에 동일하게 그 해독하기 어려운, 그래서 그것은 가능성이 높습니다 불구하고,

className anyNonReservedWord = new className(content); 
anyNonReservedWord.method(); 

// Alternatively 
className @object = new className(content); 
@object.method(); 

당신은 당신의 코드 내 method의 선언을 표시하지 않습니다 그러나, 당신은 당신이 원하는 경우, 예약 된 단어를 사용하는 @을 사용할 수 있습니다 발행물.편집 한 후


편집 : 나는 당신의 PuzzleSolver 클래스

AppNamespace

라는 네임 스페이스 내에서 두 개의 클래스를 정의했다

네임 스페이스 App하지 AppNamespace입니다. Solver에 실제 네임 스페이스를 표시하지는 않지만 네임 스페이스가 일치하지 않는다고 생각됩니다.

+0

@에 대해 몰랐습니다. 나는 그걸 사용하게 될지 의심 스럽지만, 알아두면 좋다. –

+0

@SystemDown 예 - Cory의 우수한 응답 외에 답변을 추가 한 이유입니다. –

+0

그건 내 잘못입니다. 코드를로드 할 때 클래스 및 객체의 이름을 변경했습니다. 그러나 실제 클래스 이름 지금 거기서 ... 그리고 저는 C#이 건전하다는 것을 확신합니다. 그래서 저는 메쏘드 정의를 게시하지 않았습니다. – GArchitech

4

object은 예약어이므로 이름 변수에 사용할 수 없습니다. 이름을 변경해보십시오 :

className somethingDifferent = new className(content); 
somethingDifferent.method(); 

또한, 클래스 이름을 파스칼 케이스를 사용해야하고, FTLOG는 "클래스 이름"이외의 수업 뭔가 이름을 지정합니다.

+0

나는 그 질문을하기위한 가난한 재 명명이라고 추측하고있다. – mydogisbox

+0

@mydogisbox : 나는 그렇게 희망한다! –

+0

죄송합니다, 내가 게시 한 코드에서 클래스 및 객체 이름을 변경했지만 ... 실제 코드는 게시 할 예정입니다. – GArchitech

관련 문제