问题:类之间的可访问性不一致 [英] Problem: Inconsistent accessibility between classes

查看:70
本文介绍了问题:类之间的可访问性不一致的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我有两个类之间不一致的可访问性问题。我有一个课程,它提供了一个评论列表和一个提供活动的课程。我希望将此列表作为类事件中的属性。你有什么想法解决这个问题吗?



这是P_event类:

  public   class  P_event: event  {
private double 价格;
List_comment评论;

public List_comment getset_comment // getset_comment出错
{
get
{
return 评论;
}
set
{
comment = value ;
}
} ...





和列表评论类:

< pre lang =c#> public class List_comment
{
List< Comment> ; list_comment = new 列表< Comment>();

public void add_comment(Comment c)
{
list_comment.Add(c);
}

public void ...





感谢您的帮助.. :)

解决方案

我从未见过从事件派生的类。这是不可能的。

什么是一个提出活动的课程?澄清你想要实现的目标。然后我们就可以帮助它了。

干杯

Andi

PS:一些不相关但重要的事情:我从未见过名为<$的物业c $ c> getset _... 您可以创建自己的命名方案,但我认为至少知道微软对此有何看法是值得的。请参阅开发类库的设计指南 [ ^ ],尤其是名称指南 [ ^ ],活动设计 [ ^ ]和属性设计 [ ^ ]。您甚至可以看到上述问题的解决方案。


我找到了解决此问题的方法。我错过了List_comment类( public )和P_event类的可见性,我在

 List_comment上更改了

 List_comment comment; 

comment = new List_comment();

感谢您的回复:D


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:

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:

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.. :)

解决方案

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.


I found the solution for this problem. I missed visibility on List_comment class (public) and on P_event class i changed

List_comment comment;

on

List_comment comment=new List_comment();

Thank you for your response :D


这篇关于问题:类之间的可访问性不一致的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆