2015-03-19 1 views
0

Я не могу решить проблему. Программа должна скрыть «Printfullname()» из класса employee.Элемент «methodhiding.parttimeemployee.printfullname()» не скрывает унаследованного пользователя

using System; 

namespace MethodHiding 
{ 
    public class Employee 
    { 
     public string first; 
     public string last; 

     public void PrintFullName() 
     { 
      Console.WriteLine(first + " " + last); 
     } 

    } 
    public class PartTimeEmployee : Employee 
    { 
     public new void PrintFullname() 
     { 
      Console.WriteLine(first + " " + last + "- Contractor "); 
     } 
    } 
    public class FullTimeEmployee : Employee 
    { 

    } 
    class MainClass 
    { 
     public static void Main (string[] args) 
     { 
      PartTimeEmployee PTE = new PartTimeEmployee(); 
      PTE.first = "abc"; 
      PTE.last = "Sarfraz"; 
      PTE.PrintFullName(); 
     FullTimeEmployee FTE = new FullTimeEmployee(); 
     FTE.first= "hjk"; 
      FTE.last = "poi"; 
       FTE.PrintFullName(); 

     } 
    } 
} 
+5

PrintFull ** n ** ame! = PrintFull ** N ** ame –

ответ

0

PrintFullname не существует. Возможно, вы имели в виду PrintFullName?

public class PartTimeEmployee : Employee 
{ 
    public new void PrintFullname() < this should be PrintFullName 
    { 
     Console.WriteLine(first + " " + last + "- Contractor "); 
    } 
} 
2
public virtual void PrintFullName() 
{ 
     Console.WriteLine(first + " " + last); 
} 

public override void PrintFullName() 
{ 
     Console.WriteLine(first + " " + last + "- Contractor "); 
} 

Не используйте новые, если вы не должны. Также, как отметил Евгений Подскал, C# чувствителен к регистру.