这是我的父类:
public abstract class BaseFile
{
public string Name { get; set; }
public string FileType { get; set; }
public long Size { get; set; }
public DateTime CreationDate { get; set; }
public DateTime ModificationDate { get; set; }
public abstract void GetFileInformation();
public abstract void GetThumbnail();
}
Run Code Online (Sandbox Code Playgroud)
这是继承它的类:
public class Picture:BaseFile
{
public override void GetFileInformation(string filePath)
{
FileInfo fileInformation = new FileInfo(filePath);
if (fileInformation.Exists)
{
Name = fileInformation.Name;
FileType = fileInformation.Extension;
Size = fileInformation.Length;
CreationDate = fileInformation.CreationTime;
ModificationDate = fileInformation.LastWriteTime;
}
}
public override void GetThumbnail()
{
}
}
Run Code Online (Sandbox Code Playgroud)
我想当一个方法被覆盖时,我可以用它做我想做的事.有什么帮助吗?:)
SLa*_*aks 10
您无法更改已覆盖方法的签名.(协变返回类型除外)
在您的代码中,如果我运行以下内容,您会发生什么:
BaseFile file = new Picture();
file.GetFileInformation(); //Look ma, no parameters!
Run Code Online (Sandbox Code Playgroud)
会是什么filePath参数?
您应该将基本参数和派生方法更改为相同.