일관성없는 접근성 : 매개 변수 유형이 방법보다 접근성이 떨어짐 ACT, so we can carry

두 양식 사이에 객체 (기본적으로 현재 로그온 한 사용자에 대한 참조)를 전달하려고합니다. 현재 로그인 양식으로 다음 줄에 무언가가 있습니다.

private ACTInterface oActInterface;

public void button1_Click(object sender, EventArgs e)
    {
        oActInterface = new ACTInterface(@"\\actserver\Database\Premier.pad",this.textUser.Text,this.textPass.Text);

        if (oActInterface.checkLoggedIn())
        {
            //user has authed against ACT, so we can carry on
            clients oClientForm = new clients(oActInterface);
            this.Hide();
            oClientForm.Show();
        }
        else...

다음 양식 (클라이언트)에는 다음이 있습니다.

public partial class clients : Form
{
    private ACTInterface oActInt {get; set;}

    public clients(ACTInterface _oActInt)

… 내가 얻는 결과 :

Error   1   Inconsistent accessibility:
parameter type 'support.ACTInterface' is less accessible than method
'support.clients.clients(support.ACTInterface)'
c:\work\net\backup\support\support\clients.cs   20  16  support

나는 문제가 무엇인지 실제로 이해하지 못합니다. 두 필드는 모두 비공개이며 양식의 관련 공개 방법으로 액세스 할 수 있습니다. 인터넷 검색은 하나의 요소가 공개 요소이고 다른 하나는 비공개 요소를 가리 키기 때문에 실제로 도움이되지 않습니다.

도와 줄 사람 있어요?



답변

public클래스의 생성자 clientspublic있지만 유형의 매개 변수 ACTInterface가 있습니다 private(클래스에 중첩되어 있습니까?). 당신은 그렇게 할 수 없습니다. ACTInterface최소한으로 액세스 할 수 있어야합니다 clients.


답변

수업을 공개하십시오.

class NewClass
{

}

와 같다:

internal class NewClass
{

}

수업은 공개되어야합니다


답변

type과 같은 소리 ACTInterface는 아니지만 (최상위 레벨 인 경우) 또는 (다른 유형으로 중첩 된 경우 ) public기본 접근성을 사용중인 경우.internalprivate

public수정 자 유형을 지정하면 수정자가 수정됩니다.

또 다른 접근법은 유형과 메소드를 모두 internal의도하는 경우 만드는 것입니다.

문제는 필드 의 접근성 ( oActInterface)이 아니라 유형 ACTInterface자체 의 접근성입니다 .


답변

유형의 접근성은 무엇입니까 support.ACTInterface. 오류는 공개되지 않았다는 것을 나타냅니다.

서명의 일부 매개 변수 유형이 공용이 아닌 공용 메소드 서명을 노출 할 수 없습니다. 호출자가 필요한 매개 변수를 구성 할 수 없으므로 외부에서 메소드를 호출 할 수 없습니다.

당신이 할 경우 support.ACTInterface대중이이 오류를 제거합니다. 또는 가능한 경우 양식 방법의 액세스 가능성을 줄이십시오.


답변

문제는 변수가 아니라 ACTInterface 선언과 관련이있는 것 같습니다. ACTInterface가 우연히 내부로 선언 되었습니까?


답변

이 오류가 발생했을 때 “helper”클래스를 사용하는 클래스 내에서이 문제를 일으킨 public으로 선언하지 않은 “helper”클래스가있었습니다. “helper”클래스를 공개하면 다음과 같이이 오류가 해결되었습니다.

공공 서비스 클래스 {공공 서비스 클래스 (HelperClass _helper) {}}

public class HelperClass {} // 내 문제를 해결 한 public HelperClass에 주목하십시오.

이것은 이것을 만나는 다른 사람을 도울 수 있습니다.


답변

parameter type 'support.ACTInterface' is less accessible than method
'support.clients.clients(support.ACTInterface)' 

오류는 ‘support.ACTInterface’에 액세스 할 수 없음을 나타냅니다. 인터페이스를 개인용으로 만들거나 최소한 내부 용으로 만들거나 공용으로 설정했기 때문입니다.