Reputation: 101
I've looked through several posts on here, and none of the solutions I've found have worked for me. I'm trying to pass an object from form a to form b when you click a menu item, and it is giving me the error:
Error 1 Inconsistent accessibility: parameter type 'WindowsFormsApplication1.character' is less accessible than method 'WindowsFormsApplication1.CharBuilder.CharBuilder(WindowsFormsApplication1.character)'
Here is the sending form:
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;
namespace WindowsFormsApplication1
{
public partial class GVL4 : Form
{
public GVL4()
{
InitializeComponent();
}
public void mNewGame_Click(object sender, EventArgs e)
{
character MyCharacter = new character();
MyCharacter.SetIsNew();
CharBuilder NewCharacter = new CharBuilder(MyCharacter);
NewCharacter.Show();
}
}
}
And the receiving form:
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;
namespace WindowsFormsApplication1
{
public partial class CharBuilder : Form
{
character Char = new character();
public CharBuilder()
{
InitializeComponent();
}
//Overloaded Constructor
public CharBuilder(character cChar)
{
Char = cChar;
}
private void txtSect_TextChanged(object sender, EventArgs e)
{
}
private void btnSaveID_Click(object sender, EventArgs e)
{
if (Char.IsNew())
{
Char.SaveCharIdentity(txtCharName.Text, txtClan.Text, txtSect.Text, txtNature.Text, txtDemeanor.Text, txtTitle.Text, txtCoterie.Text, txtSire.Text, txtPlayerName.Text, txtCharacterID.Text, txtStatus.Text, Convert.ToInt32(txtUnspentXP.Text), Convert.ToInt32(txtEarnedXP.Text), Convert.ToInt32(txtGeneration.Text), Convert.ToInt32(txtBloodPool.Text), cbxNPC.Checked);
}
txtTestBox.Text = Char.ToString();
}
public void CharBuilder_Load(object sender, EventArgs e)
{
}
}
}
The error is on the overloaded (Public CharBuilder(character cChar))
Upvotes: 0
Views: 81
Reputation: 218877
Where is the character
class defined? I suspect it's a private class inside GVL4
? What the error is telling you is that, even you you're passing an instance of character
to CharBuilder
, CharBuilder
doesn't actually have any way of knowing what a character
object is. It's receiving an object, but it has no class to define that object.
Ensure that the character
class is known to both forms. I imagine it should just be a separate class defined elsewhere in the project, likely either public or internal, and not internal to any particular form.
Side Note: Your code is very difficult to read because you're not following C# conventions. Class/type names should begin with uppercase, local variable names should begin with lowercase.
Upvotes: 1
Reputation: 5258
You didn't post the code for your character class, but it sounds like that class is marked as something other than public
, which is why you're seeing this error. Change the declaration of your character
class to public
, and it will work.
Upvotes: 0
Reputation: 2682
It means that your character
class is less accessible than public
, like your public method is. You need to ensure the access modifiers are the same. I'm not sure of your class design, so not sure what the best route would be, but if no one is using your code as a library just make the character class public.
Upvotes: 0