Question

'm making an application for Windows 8 in C# and XAML.

I've defined two classes within a namespace called AppNamespace, and one of these classes takes a three dimensional boolean array within it's constructor:

    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
     }

So the definition can be seen above.

I've then created a new page on a gridapp called 'NewPage.xaml' and in that page there is are some textboxes which manipulate the values within the array. (There doesn't seem to be an issue here)

Then in 'NewPage.xaml.cs' when the button is clicked, it should create an instance on the class, and then run a method within the class, at the top of the "NewPage.xaml.cs" I define a three dimensional array as seen below,

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

The issue is, that the compiler recognises that "className" is a class, but says that it does not have a constructor which takes 1 parameter, and it also says:

"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"

Can anyone identify where my issue is from this information?

I've edited this to show other namespace declarations, first the declarations on "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;

Now the declarations on "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>
Was it helpful?

Solution 2

When you declare your instance, you're using object as the variable name.

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

This causes the compiler to get confused, since object is a reserved keyword (it always refers to System.Object).

You should use a better name. However, you could use @ to use the reserved word, if you desire this:

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

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

You do not show the declaration of method within your code, so that is difficult to decipher, though it's likely due to the same issue.


Edit after your edit:

I've defined two classes within a namespace called AppNamespace

Your PuzzleSolver class is in namespace App, not AppNamespace. While you don't show your actual namespace for Solver, I suspect it's a namespace mismatch.

OTHER TIPS

object is a reserved keyword and you can't use it to name variables. Try changing the name:

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

Also, you should use Pascal casing for class names, and FTLOG, name your class something other than "className".

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top