开发者

Why am I getting this error when overriding an inherited method?

Here's my parent class:

    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();

    }

And here's the class that's inheriting it:

    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;
            }
    开发者_Python百科    }

        public override void GetThumbnail()
        {

        }
    }

I thought when a method was overridden, I could do what I wanted with it. Any help please? :)


You cannot change the signature of an overridden method. (Except for covariant return types)

In your code, what would you expect to happen if I run the following:

BaseFile file = new Picture();
file.GetFileInformation();  //Look ma, no parameters!

What would the filePath parameter be?

You should change the parameters of the base and derived methods to be identical.


You have a parameter in the derived class that's not declared in the parent class. (string filepath in the getFileInformation method)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜