Otrzymuję ten błąd podczas tworzenia metody public
dla klasy jawnie implementującej interface
. Mam obejście: usuwając jawną implementację metody PrintName
. Ale jestem zaskoczony, dlaczego dostaję tego błędu.Błąd kompilacji: "Modyfikator" publiczny "jest nieprawidłowy dla tego elementu" podczas jawnego implementowania interfejsu
Czy ktoś może wyjaśnić błąd?
Kod Biblioteki:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Test.Lib1
{
public class Customer : i1
{
public string i1.PrintName() //Error Here...
{
return this.GetType().Name + " called from interface i1";
}
}
public interface i1
{
string PrintName();
}
interface i2
{
string PrintName();
}
}
kod dla konsoli testowy Zastosowanie:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Test.Lib1;
namespace ca1.Test
{
class Program
{
static void Main(string[] args)
{
Customer customer = new Customer();
Console.WriteLine(customer.PrintName());
//i1 i1o = new Customer();
//Console.WriteLine(i1o.printname());
//i2 i2o = new Customer();
//Console.WriteLine(i2o.printname());
}
}
}
(c jak I1) .M(); // nie ma problemu To prawda, ale co jeśli chcesz uzyskać dostęp do metody M poza assambly, to jest niedostępne? – Lalit
@Lalit, jest dostępny wszędzie tam, gdzie I1 jest dostępny. Także w innych zespołach. –
Interfejs I1 jest dostępny poza assambly, ale metoda M dla klasy C jest niedostępna ouuside, sprawdź przeglądarkę klasy, a także jest oznaczona jako prywatna. – Lalit