首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > C# >

类继承出现一个很奇怪的有关问题,高人指教

2012-01-03 
类继承出现一个很奇怪的问题,高人指教我新写一个类,从FileSystemEventArgs继承过来,但是出错提示FileSyste

类继承出现一个很奇怪的问题,高人指教
我新写一个类,从FileSystemEventArgs继承过来,但是出错提示FileSystemEventArgs方法没有采用“0”个参数的重载,是怎么回事啊!我继承的其它类没有这个现象啊!


using   System;
using   System.Collections.Generic;
using   System.Text;
using   System.IO;

        class   FileSystemEventArgs_   :   FileSystemEventArgs
        {
                private   static   string   path   =   " ";

                public   static   string   sVar1
                {
                        get
                        {
                                return   path;
                        }
                        set
                        {
                                path   =   value;
                        }
                }
        }


[解决办法]
你从FileSystemEventArgs继承子类,应该编写它的构造函数,如果没有编写,那么因为FileSystemEventArgs的构造函数有且仅有一个有两个参数的构造函数,而没有默认的无参构造函数.

你需要这样编写:

class FileSystemEventArgs_ : FileSystemEventArgs
{
private static string path = " ";

public FileSystemEventArgs_():base(WatcherChangeTypes.All, null, null)
{

}
public static string sVar1
{
get
{
return path;
}
set
{
path = value;
}
}
}
[解决办法]
class FileSystemEventArgsDemo : FileSystemEventArgs
{
public FileSystemEventArgsDemo():base(System.IO.WatcherChangeTypes.All, null, null)
{

}
private static string path = " ";

public static string sVar1
{
get
{
return path;
}
set
{
path = value;
}
}
}

热点排行