Sponsored By

Sign in to follow this  
iccaros

C# Class Question

Recommended Posts

ok I have a program I am creating and I added a class called invatory, I get this error when I try to use the class

Error	1	'cSharp_Adventure.Invatory.Invatory()' is inaccessible due to its protection level	C:\Documents and Settings\huskeyw\My Documents\Visual Studio 2005\Projects\cSharp Adventure\cSharp Adventure\Program.cs	18	33	cSharp Adventure

here is my code so far

Invatory.cs

using System;
using System.Collections.Generic;
using System.Text;

namespace cSharp_Adventure
{

public class Invatory
{
public string[] invatory;
Invatory()
{
invatory = new string[5] {"Empty","Empty","Empty","Empty","Empty"};
}

public void setInvatory(int itemNumber, string item)
{
invatory[itemNumber] = item;
}

}
}

form1.cs

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;


namespace cSharp_Adventure
{
public partial class MainForm : Form
{
//Decare runtime varables
Invatory invatory = new Invatory();
//End runtime varables

public MainForm()
{
InitializeComponent();
}

private void ObjectWord_TextChanged(object sender, EventArgs e)
{

}

private void CommandWord_TextChanged(object sender, EventArgs e)
{

}
}

any help as to why a public class is protected ??

Share this post


Link to post
Share on other sites

It's the constructor. You don't have an access qualifier on it.

Share this post


Link to post
Share on other sites

Thanks, now I feel dumb... :)

I had thought about it, but for some reason I thought construtors did not need one as they have no return type..

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this