1

I am getting an error as followed: Inconsistent accessibility: property type 'AudioDevices.Tracks.track.Time' is less accessible than property 'AudioDevices.Tracks.track.length'

I have no clue what it is, or how i can fix it. Anybody that can help me?

This is all the code i have, [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 



}

}

ckundo
  • 1,551
  • 10
  • 12
user1859829
  • 53
  • 3
  • 8
  • It has been fixed! Thanks for the help everybody! – user1859829 Apr 17 '13 at 12:54
  • for future reference: http://stackoverflow.com/questions/3763612/default-visibility-for-c-sharp-classes-and-members-fields-methods-etc – Steve Apr 17 '13 at 12:55
  • As an FYI, the *reason* this is an error is that some other class will be able to see `Length` (since it is public) but not `Time` (since it is private). Basically, your original code says: *Anyone can set the length by passing in a Time object. What is a Time object? That's a secret! ::Sticks out tongue::* – Brian Apr 17 '13 at 20:54

3 Answers3

3

You've got a public property here:

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

... but the type of that property is Time, which is a private type:

struct Time {
   ...
}

(It's private because it's a nested type; if it were declared as a top-level type it would be internal by default, which would still have the same problem.)

Public member signatures can't refer to private or internal types anywhere in the parameter types or return type. The member simply wouldn't be meaningful to the caller if they were in a different assembly.

So, the fix is to either make Time a public type (and I'd recommend extracting it as a top-level type at the same time) or to make Time a private property.

Jon Skeet
  • 1,421,763
  • 867
  • 9,128
  • 9,194
  • wow, i changed it to public struct time. and it worked. i finally know what the problem was. And why there was a problem. thank you! – user1859829 Apr 17 '13 at 12:53
0

This might be because you are using a construct Time.

Try to alter your code like:

  public Time Length{
        set { length = new Time(value); }
    }
Soner Gönül
  • 97,193
  • 102
  • 206
  • 364
SHAKIR SHABBIR
  • 1,295
  • 1
  • 14
  • 25
0

From MSDN;

The access level for class members and struct members, including nested classes and structs, is private by default.

So, your Time struct is private by default.

On this part;

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

You are trying to create public property the type of private struct. You can't do that. For fixing it,

  • Change your Length property access modifier public to private.

or

  • Set your Time struct access modifier to public.
Soner Gönül
  • 97,193
  • 102
  • 206
  • 364