1

我收到如下错误:不一致的可访问性:属性类型“AudioDevices.Tracks.track.Time”比属性“AudioDevices.Tracks.track.length”更难访问

我不知道它是什么,或者我该如何解决它。有人可以帮助我吗?

这是我所有的代码,[模板=类库]:

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 



}

}

4

3 回答 3

3

你在这里有一个公共财产:

public Time Length{
    set { length = value; }
}

...但是该属性的类型是Time,它是私有类型:

struct Time {
   ...
}

(它是私有的,因为它是一个嵌套类型;如果它被声明为顶级类型,默认情况下它会是内部的,这仍然会有同样的问题。)

公共成员签名不能在参数类型或返回类型中的任何位置引用私有或内部类型。如果成员在不同的程序集中,则该成员对调用者根本没有意义。

因此,解决方法创建Time一个公共类型(我建议同时将其提取为顶级类型)创建Time一个私有属性。

于 2013-04-17T12:50:37.287 回答
0

这可能是因为您使用的是构造时间。

尝试更改您的代码,例如:

  public Time Length{
        set { length = new Time(value); }
    }
于 2013-04-17T12:52:21.280 回答
0

来自MSDN

默认情况下,类成员和结构成员(包括嵌套类和结构)的访问级别是私有的。

所以,你的Time结构是private默认的。

在这部分;

public Time Length
{
    set { length = value; }
}

您正在尝试创建结构public类型的属性private。你不能那样做。为了修复它,

  • Length将您的属性访问修饰符更改publicprivate.

或者

  • 将您的Time结构访问修饰符设置为public.
于 2013-04-17T12:58:53.713 回答