Is Inaccessible Due to Its Protection Level

is inaccessible due to its protection level

In your base class Clubs the following are declared protected

  • club;
  • distance;
  • cleanclub;
  • scores;
  • par;
  • hole;

which means these can only be accessed by the class itself or any class which derives from Clubs.

In your main code, you try to access these outside of the class itself. eg:

Console.WriteLine("How far to the hole?");
myClub.distance = Console.ReadLine();

You have (somewhat correctly) provided public accessors to these variables. eg:

public string mydistance
{
get
{
return distance;
}
set
{
distance = value;
}
}

which means your main code could be changed to

Console.WriteLine("How far to the hole?");
myClub.mydistance = Console.ReadLine();

method XXX is inaccessible due to its protection level

You could try to resolve ILoggerService instead of a specific implementation.

If you resolve concrete types instead of interfaces, you're using only half of the power of unity or dependency injection/inversion of control in general.

BTW: the implementations should most of the time be internal, while interfaces on the other hand tend to be public.

Member variable inaccessible due to its protection level

While you have a public class, the property you created is private. The default when you don't specify an access modifier on a class is private. Interfaces do not allow access modifiers as everything is assumed public (otherwise the interface would not be useful).

Use this instead on your DatabaseSettings class (the interface is fine):

public string connection { get; set; }

Also, your interface is defined as a class. Define it as an interface instead:

public interface IDatabaseSettings
{
...
}

Method inaccessible due to its protection level

Your methods are private.
You have to write public in front of the method you want to access from outside the class.

public void ReduceHealth()
{
...
}

Inaccessible due to protection level in C#

Declare your class as public and non-Abstract and I think it will solve your problem.

public class LoggerFile

By the way, why is it even Abstract. If you only have some static members in it, maybe you should just turn it to static itself.

Though in most logger implementations, it makes sense to follow the singleton pattern (one of the few cases)

WebHost' is inaccessible due to its protection level

From the documentation, WebHost is in the namespace Microsoft.AspNetCore. But in your code, It hasn't the using to this namespace.

In Visual Studio, you can try Go to definition on WebHost to discover where the type come.

As sujested by @leiflundgren, as your code has the using Microsoft.AspNetCore.Hosting, then the compiler thinks you want use Microsoft.AspNetCore.Hosting.WebHost.

https://github.com/dotnet/aspnetcore/blob/main/src/Hosting/Hosting/src/Internal/WebHost.cs

namespace Microsoft.AspNetCore.Hosting;

internal sealed partial class WebHost : IWebHost, IAsyncDisposable
{
....
}

But this class has the scope internal, then it isn't exposed and can be used by your code. Hence the following error :

WebHost is inaccessible due to its protection level.

Inaccessible due to its protection level?

Even though the variables are in a public class, they must be declared as public as they are private by default.

See: Access Modifiers

Class members, including nested classes and structs, can be public,
protected internal, protected, internal, or private. The access level
for class members and struct members, including nested classes and
structs, is private by default
.

It is best practice to use capitalized names and properties for public variables.

public A { get; set; }

Properties allow you to control the access of reading/writing of the member, as well as adding logic when they are read or set.

Function is inaccessible due to its protection level in C#

Change the following:

private void FunctionName(object sender, KeyEventArgs e)

to

public void FunctionName(object sender, KeyEventArgs e)

You generally can't access a private method from outside its class. Read here for further information



Related Topics



Leave a reply



Submit