PDA

View Full Version : Resolved C# troubles with getter/setter of a List<T>


jellev
10-08-2009, 05:01 PM
Hi there,

I'm working on a program with some classes.
I made my mainclass a singleton, called GameInput.
This class has a private List<Group> of some groups(objects).

when I create the getter and setter there is given an error:
Error 1 Inconsistent accessibility: property type 'System.Collections.Generic.List<GameInput.Group>' is less accessible than property 'GameInput.GameInput.groepen' G:\Programming\userfull\GameInput\GameInput\GameInput.cs 34 22 GameInput


this is my code of my main class:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;

namespace GameInput
{
public sealed class GameInput
{
static GameInput gi = null;
private List<Group> groepen_;

private GameInput()
{
groepen_ = new List<Group>();
groepen_.Add(new Group("z"));
}

public static GameInput GI
{
get
{
if (gi == null)
{
gi = new GameInput();
}
return gi;
}
}
// here its going wrong...
public List<Group> groepen { get { return groepen_; } set { groepen_ = value; } }


public void printGroepen()
{
int i = 0;
foreach (Group obj in groepen_)
Console.WriteLine(" [{0}]: {1}", i++, obj.Name);
Console.WriteLine();
}

}
}


Does anyone knows what's going wrong?

oracleguy
10-08-2009, 05:14 PM
The problem is with your Group object, wherever you have it declared, it isn't public. Which means when you have a public class that has a public property or method that uses it, outside of the namespace no one would be able to use it because they couldn't access the Group object.

jellev
10-08-2009, 05:26 PM
Thx

was a little dumb of me...

greetz