读书人

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

发布时间: 2012-01-03 22:16:06 作者: rapoo

类继承出现一个很奇怪的问题,高人指教
我新写一个类,从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;
}
}
}

读书人网 >C#

热点推荐