C
C#2y ago
bernie2024

✅ Strange error when trying to retrun a class type variable through a public method

Hi there, I am new to C# and while working on this method:
namespace InventoryMaintenance
{
public partial class frmNewInventoryItem : Form
{
InventoryItem invItem = null;

public frmNewInventoryItem()
{
InitializeComponent();
}

public InventoryItem GetNewItem()
{
this.ShowDialog();

return invItem;
}
private void BtnSave_Click(object sender, EventArgs e)
{

}

private void BtnCancel_Click(object sender, EventArgs e)
{

}
}
}
namespace InventoryMaintenance
{
public partial class frmNewInventoryItem : Form
{
InventoryItem invItem = null;

public frmNewInventoryItem()
{
InitializeComponent();
}

public InventoryItem GetNewItem()
{
this.ShowDialog();

return invItem;
}
private void BtnSave_Click(object sender, EventArgs e)
{

}

private void BtnCancel_Click(object sender, EventArgs e)
{

}
}
}
The method public InventoryItem GetNewItem(){} is displaying a build error which says "Inconsistent accessibility: return type 'inventoryitem' is less accessible than method 'GetNewItem()" I dont understand what it means, the class must be public for later use. Am I doing this wrong?
2 Replies
jcotton42
jcotton422y ago
GetNewItem is public, but InventoryItem is less than public i.e. it's something like internal class InventoryItem or class InventoryItem instead of public class InventoryItem
bernie2024
bernie20242y ago
im sorry I am struggling to interperet that give me a moment ah ok I see now thank you very much!