Click here to Skip to main content
15,905,323 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi,
i have problem about inconsistent accessibility between two classes. I have one class, which presents a list of comment and a class, that presents an event. I would like to have this list as an attribute in class event. Do you have any idea for solution of this problem?

This is P_event class:
C#
public class P_event : event{
	        private double price;
	        List_comment comment;
	 
	        public List_comment getset_comment //there is error at "getset_comment"
	        {
	            get
	            {
	                return comment;
	            }
	            set
	            {
	                comment= value;
	            }
	        }...


and list comment class:
C#
public class List_comment
	    {
	        List<Comment> list_comment= new List<Comment>();
	 
	        public void add_comment(Comment c)
	        {
	            list_comment.Add(c);
	        }
	 
	        public void...


Thanks for the help.. :)
Posted
Comments
Thomas Daniels 13-Oct-13 11:31am    
Which error do you get?
vezo11 13-Oct-13 11:37am    
ohh sory i forgot... error is: Error 1 Inconsistent accessibility: property type 'N1_V.List_comment' is less accessible than property 'N1_V.P_event.getset_comment' C:\... :)
David_Wimbley 13-Oct-13 11:55am    
Its because by default no accessor at the front of a method is considered Private.

You need to change List<comment> list_comment= new List<comment>(); to public List<comment> list_comment= new List<comment>();

The error is telling you getset_comment is public and list_comment is private.
vezo11 13-Oct-13 12:22pm    
Thanks for the explanation.

But when i change List list_comment= new List(); to public List list_comment= new List();, compiler give me new error - in List_comment :/

in: public List<comment> list_comment = new List<comment>();

and: public void add_comment(Comment c)

I've never seen a class deriving from an event. That's not possible.
What is "a class that presents an event"? Clarify what you want to achieve first. Then we can help soving it.
Cheers
Andi
PS: Some unrelated but important thing: I've never seen properties named getset_... You may invent your own naming scheme but I think it's worth to at least know what Microsoft says about it. See Design Guidelines for Developing Class Libraries[^], especially Guidelines for Names[^], Event Design[^] and Property Design[^]. You may even see solutions for your question above.
 
Share this answer
 
v3
Comments
vezo11 13-Oct-13 12:27pm    
Thanks Andreas :) I have class P_event, which presents for example a concert... I want to save a list of comments(list_comment) for each event especially in the P_event as an attribute (like a: List_comment comment;), and then i want to save each P_event on list of events :)
Andreas Gieriet 13-Oct-13 12:55pm    
You class event in the above example is written in lower case which clashes with the keyword event. If this is a typo, fix it please in your question (use the [Imporove question] link).
And: the term attribute is used with another meaning in .Net environment. Do you mean Property?
Why do you derive from Event? I think this Event class causes the problems. Show that code too, please.
From a design point of view, you better employ composition instead of derivation. I.e. an event does not have a comment, but rather a comment relates to an Event. So, you have Events plus you have Comments that relate to an Event.
Cheers
Andi
Sergey Alexandrovich Kryukov 13-Oct-13 20:25pm    
You are right, a 5.
Note that OP did not accept it, but presented an "answer", which is just a fake, and even accepted it formally (what a shame!).
—SA
Andreas Gieriet 14-Oct-13 2:32am    
Thanks for your 5! Newbies in CP sometimes really do "strange" things...
Cheers
Andi
I found the solution for this problem. I missed visibility on List_comment class (public) and on P_event class i changed
C#
List_comment comment;
on
C#
List_comment comment=new List_comment();
Thank you for your response :D
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 13-Oct-13 20:23pm    
This "answer" is pure fake, totally unrelated to the question.
—SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900