© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•4y ago•
7 replies
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?
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

✅ Can a variable be of a type of variable or class?
C#CC# / help
3y ago
❔ ✅ public class
C#CC# / help
4y ago
❔ Pass variable type as class parameter
C#CC# / help
3y ago