我收到如下错误: 可访问性不一致:属性类型'AudioDevices.Tracks.track.Time'的可访问性低于属性'AudioDevices.Tracks.track.length'
我不知道它是什么,或者我如何解决它。有人可以帮助我吗?
这是我的所有代码,[template = class library]:
namespace AudioDevices.Tracks
{
public class Track
{
#region STRUCT
private int id;
private string name;
private string artist;
private string albumSource;
private Time length;
private category style;
public enum category{
Ambient, Blues, Country, Disco, Electro, Hardcore, HardRock, HeavyMetal, Hiphop, Jazz, Jumpstyle,
Klassiek, Latin, Other, Pop, Punk, Reggae, Rock, Soul, Trance, Techno
};
#endregion
#region GET/SET
public int Id{
get { return id; }
set { id = value; }
}
public string Name{
get { return name; }
set { name = value; }
}
public string Artist{
get { return artist; }
set { artist = value; }
}
public string AlbumSource{
get { return albumSource; }
set { albumSource = value; }
}
public Time Length{
set { length = value; }
}
public string DisplayTime
{
get { return length.ToString(); }
}
public category Style
{
get { return style; }
set { style = value; }
}
#endregion
#region TIME CONSTRUCTOR
struct Time
{
int seconds;
int minutes;
int hours;
public Time(int seconds)
{
this.seconds = seconds;
this.minutes = 0;
this.hours = 0;
}
public Time(int seconds, int minutes)
{
this.seconds = seconds;
this.minutes = minutes;
this.hours = 0;
}
public Time(int seconds, int minutes, int hours)
{
this.seconds = seconds;
this.minutes = minutes;
this.hours = hours;
}
public override string ToString()
{
return hours + ":" + minutes + ":" + seconds;
}
}
#endregion
#region TRACK CONSTRUCTOR
public Track(){ }
public Track(int id)
{
this.id = id;
}
public Track(int id, string name)
{
this.id = id;
this.name = name;
}
public Track(int id, string name, string artist)
{
this.id = id;
this.name = name;
this.artist = artist;
}
#endregion
#region GetLength
public string GetLength()
{
return length.ToString();
}
public int GetLengthInSeconds(int seconds, int minutes, int hours){
int SecondsToSeconds = seconds;
int MinutesToSeconds = minutes * 60;
int HoursToSeconds = hours * 3600;
int TotalSeconds = HoursToSeconds + MinutesToSeconds + SecondsToSeconds;
return TotalSeconds;
}
#endregion
}
}
答案 0 :(得分:3)
你在这里有 public 属性:
public Time Length{
set { length = value; }
}
...但该属性的类型为Time
,这是私有类型:
struct Time {
...
}
(它是私有的,因为它是一个嵌套类型;如果它被声明为顶级类型,它默认是内部的,这仍然会有同样的问题。)
公共成员签名不能在参数类型或返回类型中的任何位置引用私有或内部类型。如果调用者在不同的程序集中,该成员对调用者来说根本就没有意义。
所以,修复是要么使Time
成为公共类型(我建议同时将其提取为顶级类型)或< / em>使Time
成为私有财产。
答案 1 :(得分:0)
这可能是因为您正在使用构造时间。
尝试改变您的代码,如:
public Time Length{
set { length = new Time(value); }
}
答案 2 :(得分:0)
来自 MSDN ;
类成员和结构成员的访问级别,包括 嵌套的类和结构,默认为私有。
因此,您的Time
结构默认为private
。
在这一部分;
public Time Length
{
set { length = value; }
}
您正在尝试将public
属性创建为private
结构的类型。你不能这样做。为了解决它,
Length
媒体资源访问修饰符public
更改为private
。或
Time
结构访问修饰符设置为public
。