Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 904911
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T16:07:45+00:00 2026-05-15T16:07:45+00:00

If I declare an interface, or a type as private in one file, is

  • 0

If I declare an interface, or a type as private in one file, is it private to that file or the namespace?

The compiler generates an error for File2: ‘Error 14 Inconsistent accessibility: parameter type ‘DIDemo1.IImageRepository’ is less accessible than method ‘DIDemo1.ImageGetter.ImageGetter(DIDemo1.IImageRepository)’

What I don’t understand is that MyClass can use the interface but ImageGetter class cannot.

File1:

namespace DIDemo1 {

    interface IImageRepository {

        Image[] GetImages();
    }

    public class MyClass : IImageRepository {

        #region IImageRepository Members

        public Image[] GetImages() {
            return new Image[] { };
        }

        #endregion
    }
}

File2:

namespace DIDemo1 {

    public class ImageGetter {

        IImageRepository _repo;

        public ImageGetter(IImageRepository repository) {
            _repo = repository;
        }

        public Image[] GetImages() {

            return _repo.GetImages();
        }
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T16:07:45+00:00Added an answer on May 15, 2026 at 4:07 pm

    What I don’t understand is that MyClass can use the interface but ImageGetter class cannot.

    ImageGetter can use the interface, it just can’t present it in one of its method signatures which are more accessible. Likewise if MyClass tried to use it in one of its method signatures you’d get the same error. Read below.


    Top level interfaces, structs, and classes default to internal access. To fix your problem put public before your interface declaration.

    internal types in C# are accessible only within the same assembly.
    You can’t use a more restrictive access modifier in a less restrictive signature for obvious reasons. (How could someone who can’t access the more restrictive type call the function for example?)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.