Winform和一个附加的类问题 [英] Winform and an added class question

查看:78
本文介绍了Winform和一个附加的类问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Form.cs中创建了代码,并添加了一个类(整个过程充当MVC模型,文件执行文件的逻辑,另一个文件通过WinForm的更改进行说明.问题是,与控制台应用程序时,出现错误,我不明白为什么要获得错误

我得到这个错误:

I created code in the Form.cs and I added a class, (the whole thing acts as an MVC model, file executes the logic of the file, the other file illustrates it with WinForm changes. Problem is, as oppose to a console applications, I get mistakes that I don''t understand why I get them

I get this mistake:


错误2不一致的可访问性:参数类型"WindowsFormsApplication1.Pieces [*,*]"的访问方式比方法"WindowsFormsApplication1.ChessBoard.PrintPieces(WindowsFormsApplication1.Pieces [*,*])" D:\ Documents and Settings \ Dima \ My Documents \ Visual Studio 2008 \ Projects \ ChessBoardGame \ ChessBoardGame \ ChessBoard.cs 1135 21 ChessBoardGame

Error 2 Inconsistent accessibility: parameter type ''WindowsFormsApplication1.Pieces[*,*]'' is less accessible than method ''WindowsFormsApplication1.ChessBoard.PrintPieces(WindowsFormsApplication1.Pieces[*,*])'' D:\Documents and Settings\Dima\My Documents\Visual Studio 2008\Projects\ChessBoardGame\ChessBoardGame\ChessBoard.cs 1135 21 ChessBoardGame




我在Form类中使用了一种方法:




I used one method in my Form class:

public void PrintPieces(Pieces [,] pieces)
{
}



在class2中我这样称呼
C#语法(切换纯文本)



and in the class2 I call it like this
C# Syntax (Toggle Plain Text)

public static void ExecuteAll(int rowStart,int columnStart,int rowEnd,int columnEnd) {
  Pieces[,] pieces = ChessBoard();
  ChessBoard chessB = new ChessBoard();
  chessB.PrintPieces(ChessBoard());
}



为什么会出错?


哦,该死.我现在改变了.现在错误消失了.
这是否意味着我可以毫无问题地使用两个代码的元素.我希望Form.cs在WinForm上显示数据,并添加为执行代码而添加的类.



Why is it a mistake?


Oooh, damn. I changed it now. Now the mistake is gone.
Does it mean that I can use the elements of both codes with no problem. I want the Form.cs to present the data on WinForm and the class that I have added to perform the code

推荐答案

这是一个错误,因为您的公共方法具有参数"Pieces"类,该参数本身并不公开.

这意味着该方法永远无法公开调用,因为无法提供所需的参数.

更改方法的定义以匹配"Pieces"的可用性,或者也将"Pieces"类设为公共.

顺便说一句,我从方法参数中假设"Pieces"类在每个实例中代表一个棋子.这很有意义,也是一件好事.但是,该名称意味着它可以容纳多个部件.通常,单个对象的实例将具有单数名称,而不是复数形式,从而允许将复数形式用于集合.我建议您将名称更改为"Piece"或可能的名称为"ChessPiece".
It is a mistake because your public method has as a parameter a class "Pieces" which is not itself publicly available.

It means that the method can never be called publicly, because it is impossible to supply the required parameter.

Change the definition of your method to match the availability of "Pieces" or make the "Pieces" class public as well.

By the way, I assume from the method parameters that the "Pieces" class represents a single chess piece with each instance. That makes a lot of sense, and is a good thing. However, the name implies that it holds more than one piece. Normally, an instance of a single object would have a singular name, rather than plural, allowing the plural to be used for a collection. I suggest that you change the name to "Piece" or possibly "ChessPiece".


您有public 方法,但class Pieces 没有.我假设它是private internal.将其设置为public ,一切正常.
You havea public method but the class Pieces is not. I assume its either private or internal. Make it public and everything should be ok.


这篇关于Winform和一个附加的类问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆