C# 可访问性不一致:参数的可访问性不如方法*第35行*

C# 可访问性不一致:参数的可访问性不如方法*第35行*,c#,C#,可访问性不一致:参数的可访问性不如方法行35 我一辈子都搞不清楚到底出了什么问题,我觉得应该公开的东西是私人的,但我找不到 using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; us

可访问性不一致:参数的可访问性不如方法行35 我一辈子都搞不清楚到底出了什么问题,我觉得应该公开的东西是私人的,但我找不到

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Net;

namespace Hangman
{
    public partial class Hangman : Form
    {
        public Hangman()
        {
            InitializeComponent();
        }

        private string word = string.Empty;
        List<Label> labels = new List<Label>();
        private int amount;

        enum BodyParts
        {
            Head,
            Body,
            Right_Arm,
            Left_Arm,
            Right_Leg,
            Left_Leg
        }

        void DrawBodyPart(BodyParts bp)
        {
            Graphics g = manPanel.CreateGraphics();
            Pen p = new Pen(Color.Blue, 2);

            if(bp == BodyParts.Head)
            {
                g.DrawEllipse(p, 40, 50, 40, 40);
            }
            else if (bp == BodyParts.Body)
            {
                g.DrawLine(p, new Point(60, 90), new Point(60, 170));
            }
            else if (bp == BodyParts.Right_Arm)
            {
                g.DrawLine(p, new Point(60, 100), new Point(90, 85));
            }
            else if (bp == BodyParts.Left_Arm)
            {
                g.DrawLine(p, new Point(60, 100), new Point(30, 85));
            }
            else if (bp == BodyParts.Right_Leg)
            {
                g.DrawLine(p, new Point(60, 170), new Point(90, 190));
            }
            else if (bp == BodyParts.Left_Leg)
            {
                g.DrawLine(p, new Point(60, 170), new Point(30, 190));
            }
        }

        void DrawHangPost()
        {
            Graphics g = manPanel.CreateGraphics();
            Pen p = new Pen(Color.Brown, 10);

            g.DrawLine(p, new Point(130, 218), new Point(130, 5));
            g.DrawLine(p, new Point(135, 5), new Point(65, 5));
            g.DrawLine(p, new Point(60, 0), new Point(60, 50));
        }

        void MakeLabels()
        {
            word = GetRandomWord();
            char[] chars = word.ToCharArray();
            int between = 330 / chars.Length - 1;

            for (int i = 0; i < chars.Length - 1; i++ )
            {
                labels.Add(new Label());
                labels[i].Location = new Point((i * between) + 10, 80);
                labels[i].Text = "_";
                labels[i].Parent = labelsGroupBox;
                labels[i].BringToFront();
                labels[i].CreateControl();
            }

            label1.Text += (chars.Length - 1).ToString();
        }

        string GetRandomWord()
        {
            WebClient wc = new WebClient();
            string wordlist = wc.DownloadString("http://www-01.sil.org/linguistics/wordlists/english/wordlist/wordsEn.txt");
            string[] words = wordlist.Split('\n');
            Random rand = new Random();
            return words[rand.Next(0, words.Length - 1)];
        }

        void ResetGame()
        {
            Graphics g = manPanel.CreateGraphics();
            g.Clear(manPanel.BackColor);
            GetRandomWord();
            MakeLabels();
            DrawHangPost();
            missedLabel.Text = "";
            guessesLabel.Text = "";
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            DrawHangPost();
            MakeLabels();

            Button[] buttons = new Button[] { buttonA, buttonB, buttonC, buttonD, buttonE, buttonF, 
            buttonG, buttonH, buttonI, buttonJ, buttonK, buttonL, buttonM, buttonN, buttonO, buttonP, 
            buttonQ, buttonR, buttonS, buttonT, buttonU, buttonV, buttonW, buttonX, buttonY, buttonZ, };
            foreach (Button btn in buttons)
            {
                //common code for all the buttons:
                btn.Click += new EventHandler(buttons_Click);
            }
        }

        private void buttons_Click(object sender, EventArgs e)
        {
            Button button = sender as Button;
            char letter = button.Text.ToLower().ToCharArray()[0];

          /*  if (!char.IsLetter(letter))
            {
                button.Enabled = true;
                MessageBox.Show("Only letters.");
                return;
            } */
            if (word.Contains(letter))
            {
                char[] letters = word.ToCharArray();

                for (int i = 0; i < letters.Length; i++)
                {
                    if (letters[i] == letter)
                    {
                        labels[i].Text = letter.ToString();
                    }
                }

                foreach(Label label1 in labels)
                {
                    if (label1.Text == "_") return;
                    MessageBox.Show("You Won!");
                    ResetGame();
                }
            }
            else
            {
                missedLabel.Text += letter.ToString() + ", ";
                DrawBodyPart((BodyParts)amount);
                amount++;
                if (amount == 6)
                {
                    MessageBox.Show("You lost. The word was: " + word);
                    ResetGame();
                }
            }
        }
    }
}

如果您没有为方法签名默认值提供访问修饰符,它将是私有的,因此如果您试图在类之外访问,它将显示可访问性错误。。您需要将访问修饰符从默认更改为公共


注意:如果您试图在类内调用此方法,则不会有问题,否则您需要更改访问修饰符

行是:void DrawBodyPartBodyParts bp方法的默认访问器是私有的,因此我无法找出问题所在,您是否尝试为DrawBodyPart方法指定私有访问器?我尝试了公共void DrawBodyPartBodyParts bp和私有void DrawBodyPartBodyParts bp。我在其他中的调用是否有问题{missedLabel.Text+=letter.ToString+,;DrawbodyPartsAmount;?否,如果方法DrawBodyPart定义为私有,则该方法不可能出现参数不易访问的错误。这真是奇怪,您是否尝试重新生成解决方案和/或重新打开visual studio?我将其更改为pPublic void DrawBodyPartBodyParts bp,但当我在else中调用它时,似乎仍然会出现错误{missedLabel.Text+=letter.ToString+,;DrawBodyPartsAmount;现在是否也存在问题?我将所有方法更改为public,现在唯一私有的是Form1\u load,以及单击按钮