c# - 编译器找不到方法名

标签 c# xaml windows-8 assembly-references

正在使用 C# 和 XAML 制作适用于 Windows 8 的应用程序。

我在名为 AppNamespace 的命名空间中定义了两个类,其中一个类在其构造函数中采用三维 bool 数组:

    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”顶部如下所示的三维数组,

    // 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();
      }
}

问题是,编译器认识到“className”是一个类,但表示它没有采用 1 个参数的构造函数,它还表示:

"ProjectName.className does not contain a definition for "method and no extension method "method" accepting a first argument of type ProjectName.className could be found (are you missing a using directive or assembly reference"

谁能根据这些信息确定我的问题出在哪里?

我对此进行了编辑以显示其他 namespace 声明,首先是“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>

最佳答案

object 是保留关键字,您不能用它来命名变量。尝试更改名称:

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

此外,您应该对类名使用 Pascal 大小写,并使用 FTLOG 将您的类命名为“className”以外的名称。

关于c# - 编译器找不到方法名,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13885564/

相关文章:

c# - 将字符串拆分为具有特定数量元素的数组,c#

c# - 在 C# 中,如何删除被另一个进程锁定的文件?

silverlight - 如何在 Silverlight 中将资源字符串绑定(bind)到 Xaml

c# - 如何在折线图中显示附加点信息?

javascript - 捕捉 Windows 应用商店应用程序时从 GridView 切换到 ListView

c - 如何在 Windows 8 上安装 C 编译器?我不想使用 IDE

xml - 使用 xmlsec1 验证 Windows 8 应用内购买收据

c# - asp.net中调度任务的方法(不用写windows scheduler)

c# - Autocad .NET - 扩展命令行

c# - 带有 CheckBox 数据模板的 WPF ListBox - Checkbox 的绑定(bind)内容属性不起作用