将参数从A类方法传递到B类

时间:2012-12-03 06:30:18

标签: c# parameters parameter-passing

//Class A
void OnChanged(object source, FileSystemEventArgs e)
{
XmlTextReader reader = new XmlTextReader("?"); <- How will I pass the "file" variable from Class B?
}

//Class B
public static bool myMethod(FileInfo file)
{
//some codes here
return false;
}

我知道你必须为此传递一些属性来传递变量,但我不确定从哪里开始。添加一些代码可以帮助我更好地理解属性。

1 个答案:

答案 0 :(得分:1)

//Class B
public static FileInfo myFileProperty
{
   get;
   set;
}

public static bool myMethod(FileInfo file)
{
//some codes here
myFileProperty = file;
return false;
}


//Class A
void OnChanged(object source, FileSystemEventArgs e)
{

XmlTextReader reader = new XmlTextReader(ClassB.myFileProperty);
}